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 c305d53 commit d649798Copy full SHA for d649798
remove-nth-node-from-end-of-list/hu6r1s.py
@@ -0,0 +1,20 @@
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
+class Solution:
7
+ def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
8
+ length = 0
9
+ node = head
10
+ while node:
11
+ length += 1
12
+ node = node.next
13
+
14
+ dummy = ListNode(None, head)
15
+ node = dummy
16
+ for _ in range(length - n):
17
18
19
+ node.next = node.next.next
20
+ return dummy.next
0 commit comments