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

Leetcode: Remove Nth Node From End of List

2016-08-31 16:43 591 查看
/**
* Definition for singly-linked list.
* struct ListNode {
*     int val;
*     struct ListNode *next;
* };
*/
struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
struct ListNode *first=head;
struct    ListNode *end=head;
while(n--){
end=end->next;
}
if(end==NULL){
return head->next;
}
while(end->next!=NULL){
first=first->next;
end=end->next;
}
first->next=first->next->next;
return head;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode