struct ListNode* removeNthFromEnd(struct ListNode* head, int n){
struct ListNode* dummyHead = (struct ListNode*)malloc(sizeof(struct ListNode));
dummyHead->next = head;
struct ListNode*slow=dummyHead,*fast=dummyHead;
for(int i=0;i<n+1;i++){
fast=fast->next;
}
while(fast!= NULL){
slow=slow->next;
fast=fast->next;
}
struct ListNode*temp=slow->next;
slow->next=temp->next;
free(temp);
return dummyHead->next;
}
相关文章
- 11-14【2021/6/12 刷题笔记】删除链表的倒数第 N 个结点与快慢指针
- 11-14leetcode刷题-[19]删除链表的倒数第 N 个结点
- 11-1419-删除链表的倒数第N个结点
- 11-14链表-删除链表的倒数第N个节点(双指针法)
- 11-142022/1/18 链表|| 19. 删除链表的倒数第 N 个结点
- 11-14LeetCode-019-删除链表的倒数第 N 个结点
- 11-14LeetCode: 19. 删除链表的倒数第 N 个结点
- 11-14leetcode-删除链表的倒数第N个节点,包含入栈、双指针
- 11-14day10-删除链表的倒数第 N 个结点
- 11-14LeetCode 19 删除链表的倒数第N个节点(C语言 快慢指针法 简单易懂)