标签:ini efi null 倒数 删除 code val 一起 代码实现
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* a = head;
ListNode *b =head;
int c = 1;
//令a指向第n+1个节点
while(c!=n+1){
a = a->next;
c++;
}
if(a == NULL){
ListNode * t = head;
head = head->next;
delete t;
return head;
}
//a b 同时向前走
while(a->next != NULL){
a = a->next;
b = b->next;
}
ListNode * t = b->next;
b->next = b->next->next;
delete t;
return head;
}
};
标签:ini efi null 倒数 删除 code val 一起 代码实现
原文地址:https://www.cnblogs.com/Phoenix-blog/p/10577204.html