Skip to content

Instantly share code, notes, and snippets.

@sheldonrobinson
Created October 5, 2019 02:35
Show Gist options
  • Select an option

  • Save sheldonrobinson/1bc9501a00ecd0e6c8ce6c4b6c7a411d to your computer and use it in GitHub Desktop.

Select an option

Save sheldonrobinson/1bc9501a00ecd0e6c8ce6c4b6c7a411d to your computer and use it in GitHub Desktop.
CodeSignal Solution removeKFromList
# 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