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

19. Remove Nth Node From End of List

2016-03-19 21:25 459 查看
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* first = head;
ListNode* second = head;
int i = 0;
while (second) {
i++;
second = second->next;
}
int j= 0;
if(i==n) return head->next;
while (j < i-n -1) {
first = first->next;
j++;
}
first->next = first->next->next;
return head;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: