Skip to content

Commit 4b62701

Browse files
authored
Create 19-Remove-Nth-node-from-end-of-List.py
1 parent 6f9a94d commit 4b62701

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
3+
dummy = ListNode(0, head)
4+
left = dummy
5+
right = head
6+
7+
while n > 0:
8+
right = right.next
9+
n -= 1
10+
11+
while right:
12+
left = left.next
13+
right = right.next
14+
15+
# delete
16+
left.next = left.next.next
17+
return dummy.next

0 commit comments

Comments
 (0)