Remove Duplicates from Sorted List II 链表去除重复值
来源:互联网 发布:c语言给数组赋初值 编辑:程序博客网 时间:2024/06/06 15:03
Remove Duplicates from Sorted List II
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) { if(head==NULL) return head; ListNode *helper=new ListNode(0); helper->next=head; ListNode *cur=head; ListNode *pre=helper; while(cur!=NULL) { while(cur->next!=NULL&&cur->val==cur->next->val) cur=cur->next; if(pre->next==cur) { pre=pre->next; } else { pre->next=cur->next; } cur=cur->next; } return helper->next; }};
0 0
- Remove Duplicates from Sorted List II 链表去除重复值
- Remove Duplicates from Sorted List 去除链表重复数据
- [Lintcode]Remove Duplicates from Sorted List II 删除排序链表中的重复数字 II
- Remove Duplicates from Sorted List(去除有序链表中的重复元素)
- LeetCdoe Remove Duplicates from Sorted List II移掉重复链表中的元素
- Remove Duplicates from Sorted List II 删除链表中的元素(不保留重复)
- LeetCode 82. Remove Duplicates from Sorted List II(删除链表中的重复节点)
- Remove Duplicates from Sorted List II 删除链表中的所有重复节点
- 82.leetcode Remove Duplicates from Sorted List II(medium)[链表删除重复]
- 82. Remove Duplicates from Sorted List II 删除排序链表中的重复数,重复的数全部删除
- leetCode 82.Remove Duplicates from Sorted List II (删除排序链表的重复II) 解题思路和方法
- 113.Remove Duplicates from Sorted List II-删除排序链表中的重复数字 II(中等题)
- Remove Duplicates from Sorted List II 链表移除重复值@LeetCode
- 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
- Search in Rotated Sorted Array II 旋转数组二分查找 有重复
- 现在就开始使用AngularJS的三个重要原因
- 常用sql模板
- hql 查询今日记录
- n!后面有多少个0
- Remove Duplicates from Sorted List II 链表去除重复值
- 由读一致性分析undo
- Partition List 链表的partition操作 分成2个链表
- 绑定变量
- Ubuntu Touch 修改默认Scope 背景
- crontab实用手册
- 使用Sun的FtpClient做FTP上传下载
- jsp中getAttribute()和getParameter()的区别
- YourKit Java Profiler2014剖析远程服务器(可以搞定liniux的jetty)