Skip to content

Commit bc5ed7d

Browse files
committed
Time: 0 ms (100%), Space: 17.7 MB (54.82%) - LeetHub
1 parent 14fd7a3 commit bc5ed7d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class ListNode:
2+
def __init__(self, val=0, next=None):
3+
self.val = val
4+
self.next = next
5+
6+
class Solution:
7+
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
8+
dummy = ListNode(0, head)
9+
fast = slow = dummy
10+
11+
for _ in range(n + 1):
12+
fast = fast.next
13+
14+
while fast:
15+
fast = fast.next
16+
slow = slow.next
17+
18+
slow.next = slow.next.next
19+
20+
return dummy.next

0 commit comments

Comments
 (0)