输入:head = [1,2,3,4,5], n = 2
输出:[1,2,3,5]
class Solution
{
public:
ListNode *removeNthFromEnd(ListNode *head, int n)
{
ListNode *dumpyNode = new ListNode(-1, head);
ListNode *fast = head, *slow = dumpyNode;
while (n-- > 0)
{
fast = fast->next;
}
while (fast != nullptr)
{
fast = fast->next;
slow = slow->next;
}
slow->next = slow->next->next;
return dumpyNode->next;
}
};