class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
int count=1;
ListNode* N_1th=head,*Head=head;
while(Head!=nullptr){
if(Head->next==nullptr){
if(count==n) head=head->next;
else N_1th->next=(N_1th->next)->next;
break;
}
Head=Head->next;
if(++count>=n+2) N_1th=N_1th->next;
}
return head;
}
};
leetcode(力扣)第十九题:删除链表的倒数第 N 个结点_C++
最新推荐文章于 2022-05-10 14:24:57 发布