1
# Runtime: 65 ms (Top 20.14%) | Memory: 13.9 MB (Top 70.35%)
2
# Definition for singly-linked list.
3
# class ListNode:
4
# def __init__(self, val=0, next=None):
5
# self.val = val
6
# self.next = next
7
class Solution:
8
def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:
9
if head == None:
10
return None
11
slow = head
12
fast = head
13
for i in range(n):
14
fast = fast.next
15
if fast == None:
16
return head.next
17
while fast != None and fast.next != None:
18
slow = slow.next
19
fast = fast.next
20
slow.next = slow.next.next
21
return head

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0