leetcode 083 Remove Duplicates from Sorted List
来源:互联网 发布:世界经济学家排名 知乎 编辑:程序博客网 时间:2024/06/07 20:00
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
.
Subscribe to see which companies asked this question
/** * 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 *pre=head, *cur=NULL, *ret=NULL, *retCur=NULL;for(cur=head->next; cur!=NULL; cur=cur->next) {if(cur->val != pre->val){if(ret==NULL) {ret = pre;} else {retCur->next = pre;}retCur = pre;retCur->next=NULL;}pre=cur;}if(ret==NULL) {ret = pre;} else {retCur->next = pre;}retCur = pre;retCur->next=NULL;return ret; }};
0 0
- LeetCode 083 Remove Duplicates from Sorted List
- 083 Remove Duplicates from Sorted List [Leetcode]
- LeetCode 083 Remove Duplicates from Sorted List
- LeetCode 083 Remove Duplicates from Sorted List
- leetcode 083 Remove Duplicates from Sorted List
- LeetCode 083 Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List :from LeetCode
- Leetcode - List - Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- leetcode 37: Remove Duplicates from Sorted List
- Disabling contextual LOB creation as createClob() method threw error : java.lang
- 内存管理-----伙伴系统---2
- 矩形相关操作
- 数据结构-链表-作业
- mybaties自动创建代码
- leetcode 083 Remove Duplicates from Sorted List
- pretrain ConvNet 转接和fine-tuning
- 如何在DW中设置自动列宽
- c++实验5-求和
- UVA 11478V Halum 二分答案+差分约束系统
- 我的第一个Python程序
- HDU 2053 Switch Game(数学题)
- 构建复杂的应用程序(三)—— 测试
- Nginx与Tomcat负载均衡