class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode dummyNode;
dummyNode.next = head;
ListNode* fast = &dummyNode;
ListNode* slow = &dummyNode;
while (n+1) {
fast = fast->next;
n--;
}
while (fast) {
fast = fast->next;
slow = slow->next;
}
slow->next = slow->next->next;
return dummyNode.next;
}
};
转载请注明原文地址:https://blackberry.8miu.com/read-12175.html