Skip to content

Instantly share code, notes, and snippets.

@DeviaVir
Created April 18, 2017 08:23
Show Gist options
  • Save DeviaVir/5a251625311d8f531e805491b26f11a8 to your computer and use it in GitHub Desktop.
Save DeviaVir/5a251625311d8f531e805491b26f11a8 to your computer and use it in GitHub Desktop.
"""
Delete Node at a given position in a linked list
Node is defined as
class Node(object):
def __init__(self, data=None, next_node=None):
self.data = data
self.next = next_node
return back the head of the linked list in the below method.
"""
def Delete(head, position):
if not head:
return head
if position == 0:
t = head.next
del head
return t
position -= 1
head.next = Delete(head.next, position)
return head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment