Skip to content

Instantly share code, notes, and snippets.

@neonbadger
Created March 21, 2016 02:26
Show Gist options
  • Save neonbadger/98c677bcc99def924fee to your computer and use it in GitHub Desktop.
Save neonbadger/98c677bcc99def924fee to your computer and use it in GitHub Desktop.
"""
Hackerrank solution.
Delete a node given a position.
"""
# 0 1 2 3 4
# 0 1 3 4
# 1 2 3 4
def Delete(head, position):
curr = head
prev = None
if position == 0:
head = curr.next
return head
else:
while position > 0:
prev = curr
curr = curr.next
position -= 1
prev.next = curr.next
return head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment