
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* dummy = new ListNode(0);
dummy->next = head;
ListNode* first = head;
ListNode* second = dummy;
while(n--)
{
first = first->next;
}
while (first!=nullptr)
{
first = first->next;
second = second->next;
}
second->next = second->next->next;
return dummy->next;
}
};
442

被折叠的 条评论
为什么被折叠?



