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 = val6# self.next = next7class Solution:8def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]:9if head == None:10return None11slow = head12fast = head13for i in range(n):14fast = fast.next15if fast == None:16return head.next17while fast != None and fast.next != None:18slow = slow.next19fast = fast.next20slow.next = slow.next.next21return head