# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
## 双指针同向
if not head:
return head
root = ListNode(-1)
root.next = head
q = p = root
while n:
p = p.next
n -= 1
# print(p.val)
while p.next :
q = q.next
p = p.next
q.next = q.next.next
return root.next