Created
October 5, 2019 02:35
-
-
Save sheldonrobinson/1bc9501a00ecd0e6c8ce6c4b6c7a411d to your computer and use it in GitHub Desktop.
CodeSignal Solution removeKFromList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Singly-linked lists are already defined with this interface: | |
| # class ListNode(object): | |
| # def __init__(self, x): | |
| # self.value = x | |
| # self.next = None | |
| # | |
| def removeKFromList(l, k): | |
| if l == None: | |
| return l | |
| while l != None and l.value == k: | |
| l = l.next | |
| n = l | |
| while n != None and n.next != None: | |
| if n.next.value == k: | |
| n.next = n.next.next | |
| else: | |
| n = n.next | |
| return l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment