LeetCode-Remove Duplicates from Sorted List
来源:互联网 发布:2016程序员薪资报告 编辑:程序博客网 时间:2024/04/27 15: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
.
Code:
<span style="font-size:14px;">/** * 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 *begin = head, *end = head; head = head->next; while (head != NULL) { if (head->val != end->val) { end->next = head; end = head; } head = head->next; } end->next = NULL; return begin; }};</span>
0 0
- 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
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List
- 有效的技巧提高你的谷歌AdWords的质量得分
- SSH登录异常(someone is doing something nasty)
- 用随机数计算π值
- 添加积分墙
- 有声读物给女孩如何鼓励阅读
- LeetCode-Remove Duplicates from Sorted List
- 有声读物的效率
- 有声读物的好处
- 本周学习积累:关于服务器相关软件的使用
- ubuntu上移动硬盘中没有可执行权限的解决方法
- 有声读物探索高速公路和英语的小路
- 有声读物为在旅途中的人
- 有声读物 - 适合孩子
- object转json 解决js中new Object() 转json的方法