MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / removeNthFromEnd

Method removeNthFromEnd

Array/RemoveNthNodeFromEndOfList.py:64–83  ·  view source on GitHub ↗

:type head: ListNode :type n: int :rtype: ListNode

(self, head, n)

Source from the content-addressed store, hash-verified

62
63class Solution(object):
64 def removeNthFromEnd(self, head, n):
65 """
66 :type head: ListNode
67 :type n: int
68 :rtype: ListNode
69 """
70 my_head = my_trail = head
71 for i in range(n):
72 my_head = my_head.next
73
74 if not my_head:
75 return head.next
76
77 while my_head.next:
78 my_head = my_head.next
79 my_trail = my_trail.next
80
81 my_trail.next = my_trail.next.next
82
83 return head
84# list_node = []
85# my_head = head
86# while my_head:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected