Skip to content

Commit 44381e9

Browse files
Solve : Remove Nth Node From End of List
1 parent 1bab0c4 commit 44381e9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def removeNthFromEnd(self, head, n):
3+
dummy = ListNode(0, head)
4+
fast = slow = dummy
5+
for _ in range(n):
6+
fast = fast.next
7+
while fast.next:
8+
fast = fast.next
9+
slow = slow.next
10+
slow.next = slow.next.next
11+
return dummy.next

0 commit comments

Comments
 (0)