Remove Nth Node From End of List 删除链表的倒数第n个结点
来源:互联网 发布:照片贴图软件 编辑:程序博客网 时间:2024/06/06 09:00
/**
* 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 dummy(-1);
dummy.next=head;
ListNode *prev=&dummy;
ListNode *p=head;
ListNode *q=head;
for(int i=0;i<n;i++)
{
p=p->next;
}
while(p!=NULL)
{
prev=q;
p=p->next;
q=q->next;
}
prev->next=q->next;
ListNode *temp=q;
delete q;
return dummy.next;
}
};
* 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 dummy(-1);
dummy.next=head;
ListNode *prev=&dummy;
ListNode *p=head;
ListNode *q=head;
for(int i=0;i<n;i++)
{
p=p->next;
}
while(p!=NULL)
{
prev=q;
p=p->next;
q=q->next;
}
prev->next=q->next;
ListNode *temp=q;
delete q;
return dummy.next;
}
};
0 0
- 删除链表的倒数第n个结点 Remove Nth Node From End of List
- Remove Nth Node From End of List 删除链表的倒数第n个结点
- LeetCode 19. Remove Nth Node From End of List--删除链表的倒数第n个结点
- 【Leecode】207Remove Nth Node From End of List删除倒数第N个结点
- Remove Nth Node From End of List 链表删除倒数第N个元素@LeetCode
- LeetCode(Remove Nth Node From End of List)删除链表倒数第n个节点
- Remove Nth Node From End of List 删除链表倒数第N个节点
- Leetcode Remove Nth Node From End of List 删除链表倒数第n个元素
- [LeetCode]—Remove Nth Node From End of List 删除链表的倒数第n个节点
- LeetCodet题解--19. Remove Nth Node From End of List(删除链表的倒数第n个元素)
- leetcode解题之 19. Remove Nth Node From End of List java 版(删除链表倒数第n个结点)
- leetcode:Remove Nth Node From End of List(删除链表倒数第n个节点)【面试算法题】
- #19 Remove Nth Node From End of List(删除链表倒数第N个节点)
- LeetCode[19]Remove Nth Node From End of List 删除链表倒数第n个元素
- leetcode-19. Remove Nth Node From End of List(删除链表倒数第N个节点)
- LeetCode Remove Nth Node From End of List 删除倒数第n个元素
- LintCode Remove Nth Node From End of List 删除链表中倒数第n个节点
- [LeetCode-19] Remove Nth Node From End of List(删除倒数第N个节点)
- 算法入门之分金币(求极值)
- 软件文档编写入门——软件工程视频总结(二)
- C#中配置文件的操作
- 孟晚舟:华为还没有遇到天花板
- (十三)Set类实现以及彩票机选算法实现
- Remove Nth Node From End of List 删除链表的倒数第n个结点
- java设计模式——综述
- Linux单网卡NAT代理的配置
- jQuery 到顶部
- 小程序
- C#之"0x{0:x}"
- UVa:11076 Add Again
- java设计模式1——工厂方法模式(Factory Method)
- JavaScript与Java的区别: