class Solution:
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
dummy=ListNode(0)
dummy.next=head
cur=dummy
stack=[]
while cur:
stack.append(cur)
cur=cur.next
for i in range(n):
stack.pop()
pre=stack[-1]
pre.next=pre.next.next
return dummy.next
用栈先入后出的