Leetcode137: Remove Duplicates from Sorted List II
来源:互联网 发布:网络品牌续费上海勤拙 编辑:程序博客网 时间:2024/05/16 07:29
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
For example,
Given 1->2->3->3->4->4->5
, return 1->2->5
.
Given 1->1->1->2->3
, return 2->3
.
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* deleteDuplicates(ListNode* head) { ListNode *pre,*cur; ListNode* temp = new ListNode(-1); temp->next = head; pre = temp; cur = head; while(cur && cur->next) { if(cur->val == cur->next->val) { while(cur->next && cur->val == cur->next->val) { cur = cur->next; } pre->next = cur->next; cur = cur->next; } else { pre = cur; cur = cur->next; } } return temp->next; }};
0 0
- Leetcode137: Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- Remove duplicates from sorted list II
- Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- [Shell]在一个目录及其子目录内的指定类型的文件中搜索某个字符串
- [问题]从bitbucket弄下来的C++代码该怎么用
- MyBatis:The expression 'list' evaluated to a null value
- 用词袋(bag of word)实现场景识别
- Docker使用总结
- Leetcode137: Remove Duplicates from Sorted List II
- 12 个非常实用的 jQuery 代码片段
- Android开发之如何保证Service不被杀掉
- 笔记
- ORACLE隐含列
- iOS判断CLLocationCoordinate2D对象是否可用
- 从github 下载项目 , 并且提交
- 欢迎使用CSDN-markdown编辑器
- MySQL 5.7.9 免安装配置