Remove Duplicates from Sorted List
来源:互联网 发布:羽绒服局部清洗 知乎 编辑:程序博客网 时间:2024/06/08 17:56
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
.
/** * 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 || head->next==NULL) return head; ListNode *start = head; ListNode *end = head->next; while (start!=NULL) { while (end!=NULL && start->val==end->val) { end = end->next; } start->next = end; start = start->next; end = start; } 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
- hdu 1158 Employment Planning (dp)
- 关于培养批判性思维
- openstack相关链接
- 感谢cctv,感谢百度搜索,
- cocos2d-x-3.0rc0 创建项目
- Remove Duplicates from Sorted List
- Java HashMap的死循环
- 相思柳,情倚春深处
- workers.properties配置
- cursor 的moveToFirst和moveToNext和moveToPrevious以及moveToLast
- 学习iOS开发的第18天
- c++继承中析构函数的调用顺序
- Windows下Apache与Tomcat的整合
- QObject 之 Thread依附性