# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = next# one passclassSolution:defremoveNthFromEnd(self,head:Optional[ListNode],n:int)->Optional[ListNode]:mv_tail=mv_head=headwhilen>0:n-=1mv_head=mv_head.next# when n == len(LL)# handle head = [1], n = 1, output = []# handle head = [1, 2], n = 2, output = [2]ifmv_headisNone:returnhead.nextwhilemv_head.nextisnotNone:mv_tail=mv_tail.nextmv_head=mv_head.nextmv_tail.next=mv_tail.next.nextreturnhead