您的位置:首页 > Web前端 > Node.js

19. Remove Nth Node From End of List

2016-08-17 00:27 246 查看
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* Head=new ListNode(-1);
Head->next=head;

ListNode* pre=Head,*cur=Head;
int len=0;
while(cur&&len<=n)
{
len++;
cur=cur->next;
}
while(cur)
{
cur=cur->next;
pre=pre->next;
}
pre->next=pre->next->next;
head=Head->next;
delete Head;
return head;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: