Skip to content

Commit 24c6ef1

Browse files
committed
Sync LeetCode submission - Remove Nth Node From End of List (python3)
1 parent 06db2de commit 24c6ef1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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: ListNode, n: int) -> ListNode:
8+
dummy = ListNode(0)
9+
dummy.next = head
10+
first = dummy
11+
second = dummy
12+
13+
for i in range(n+1):
14+
first = first.next
15+
16+
while first:
17+
first = first.next
18+
second = second.next
19+
20+
second.next = second.next.next
21+
return dummy.next

0 commit comments

Comments
 (0)