Remove Duplicates from Sorted List
来源:互联网 发布:php会员管理系统源码 编辑:程序博客网 时间:2024/06/05 11:34
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2
, return 1->2
.
Given 1->1->2->3->3
, return 1->2->3
.
pro:从排序链表中删除重复的节点
sol:定义cur和next指针,遍历链表,next不为NULL的时候继续遍历,当next的value与cur的value相等时,将next删除
code:
/** * 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 NULL; ListNode *cur,*next; cur=head; next=cur->next; while(next!=NULL) { if(next->val==cur->val) { cur->next=next->next; //cur=next; next=next->next; }else { cur=next; next=next->next; } } return head; }};
0 0
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove duplicates from sorted list
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- mini2440裸机程序时ADS调试开始全速运行不进main断点问题
- python 新东东 协程(yield与这个概念有关)
- 连接oracle报错“ORA-28547:connection to server failed,probable Oracle Net admin 解决办法
- thinkphp3.2 memcached 类库 使用方法
- Codeforces 2A
- Remove Duplicates from Sorted List
- Map接口及其子类
- pam会话函数详解
- VS2010/MFC入门编程八(控件Tree Control的操作)
- 规划法规范的地方
- D-HEAPS
- jquery 传递数组到后台 及 获取后台JSON数据并显示
- 你真的有必要退出吗——再说Android程序的退出功能
- JAVA引用