Created
March 21, 2016 02:26
-
-
Save neonbadger/98c677bcc99def924fee to your computer and use it in GitHub Desktop.
This file contains 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
""" | |
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