82. Remove Duplicates from Sorted List II
来源:互联网 发布:淘宝采购指数 编辑:程序博客网 时间:2024/05/21 23:00
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ //8ms ac //分两部分,重复包括首节点 //以及后部分重复的,考虑一下节点的释放class Solution {public: ListNode* deleteDuplicates(ListNode* head) { ListNode* head0=head; int m; int flag=false; while(head0&&head0->next&&head0->val==head0->next->val) { m=head0->val; while(head0&&head0->val==m) { head0=head->next; delete head; head=head0; } } if(!head) return NULL; if(!head->next) return head; ListNode* parent=head; while(head0) { if(head0->next&&head0->val==head0->next->val) { m=head0->val; while(head0&&head0->val==m) { parent->next=head0->next; delete head0; head0=parent->next; } } else { parent=head0; head0=head0->next; } } return head; }};
0 0
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- Http状态码大全(200、404、500等)
- 《Java必须知道的300个问题》读书总结
- 探索小游戏(二):英雄骨骼动画和基本操作
- 中国各主要大城市经纬度数据
- 第五周上机实践项目 项目1--三角形类雏形(5)
- 82. Remove Duplicates from Sorted List II
- 剑指offer面试题之求1到n之间1的个数
- 设置一个三角形类(2)
- 文字跑马灯
- Codeforces 658 C. Bear and Forgotten Tree 3(树的构造)
- poj 1006 中国剩余定理
- 基于REST的web service project添加spring框架
- 重载函数的运用。。。分别求两个整数平方和 及 两个实数的平方和
- MySql存储引擎