We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 781b457 commit 947c2f3Copy full SHA for 947c2f3
linkedlist/19_removeNthFromEnd.py
@@ -0,0 +1,19 @@
1
+# Definition for singly-linked list.
2
+class ListNode:
3
+ def __init__(self, val=0, next=None):
4
+ self.val = val
5
+ self.next = next
6
+
7
8
+class Solution:
9
+ def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
10
+ pre = ListNode(0, head)
11
+ left, right = pre, head
12
+ for _ in range(n):
13
+ right = right.next
14
15
+ while right:
16
+ left = left.next
17
18
+ left.next = left.next.next
19
+ return pre.next
0 commit comments