1 parent 1fead87 commit 5704bcaCopy full SHA for 5704bca
1 file changed
LeetCode/removeNthFromEnd_1.py
@@ -0,0 +1,24 @@
1
+# Definition for singly-linked list.
2
+# class ListNode(object):
3
+# def __init__(self, x):
4
+# self.val = x
5
+# self.next = None
6
+
7
+class Solution(object):
8
+ def removeNthFromEnd(self, head, n):
9
+ """
10
+ :type head: ListNode
11
+ :type n: int
12
+ :rtype: ListNode
13
14
+ dummy = ListNode(0)
15
+ dummy.next = head
16
+ first = dummy
17
+ for i in range(n + 1):
18
+ first = first.next
19
+ second = dummy
20
+ while first is not None:
21
22
+ second = second.next
23
+ second.next = second.next.next
24
+ return dummy.next
0 commit comments