/**
* 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: Remove Nth Node From End of List
最新推荐文章于 2020-02-05 13:18:56 发布