leetcode 第一刷_Remove Nth Node From End of List
来源:互联网 发布:淘宝怎么弄淘口令 编辑:程序博客网 时间:2024/04/30 10:34
链表问题里经典的双指针,一个先动,一个后动,然后同时动,无他,但手熟尔。
class Solution {public: ListNode *removeNthFromEnd(ListNode *head, int n) { if(!head) return head; ListNode *pre = head, *end = head; int tp = 0; while(tp<n&&end){ tp++; end = end->next; } if(tp<n) return head; if(tp==n&&end==NULL){ head = pre->next; delete pre; return head; }else{ while(end->next){ pre = pre->next; end = end->next; } ListNode *del = pre->next; pre->next = del->next; delete del; return head; } }};
0 0
- leetcode 第一刷_Remove Nth Node From End of List
- LeetCode 19_Remove Nth Node From End of List
- 0019_Remove Nth Node From End of List
- 19_Remove Nth Node From End of List徒手尝试#2(Done)
- LeetCode[Linked List]: Remove Nth Node From End of List
- 19. Remove Nth Node From End of List leetcode list
- [Leetcode]LeetCode 19:Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- leetcode 40: Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- Leetcode 19 Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- [LeetCode]Remove Nth Node From End of List
- LeetCode-Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List
- Java学习笔记_16_JavaBean
- SQL 列转行/list agg 列超长处理方法
- 漫谈惯性、视觉暂留、潜意识、混合动力发动机、先入为主 - 纯粹的无厘头?
- android json解析及简单例子
- Java 8的元空间
- leetcode 第一刷_Remove Nth Node From End of List
- 微信管家不显示验证码的解决方式
- C指针理解
- Leetcode 细节实现 Pascal's Triangle II
- grep学习笔记
- KMP模式匹配算法
- 关于封装的一点想法
- 熵编码 之 2. Arithmetic coding
- mangos地图管理