def remove_nth_from_end(head: Optional[ListNode], n: int) -> Optional[ListNode]:
fake_head = ListNode(0, head)
P = fake_head
while n>0 and P:
P = P.next
n=n-1
if not P: return head # less than n nodes
Q = fake_head
while P.next:
P = P.next
Q = Q.next
Q.next = Q.next.next
return fake_head.next