[LeetCode]Remove Duplicates from Sorted List
2014-01-15 20:05
337 查看
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given
Given
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) return head; ListNode *p=head,*q; while(p) { q=p->next; while(q&&p->val==q->val) q=q->next; p->next=q; p=p->next; } return head; } };
相关文章推荐
- leetcode-Remove Duplicates from Sorted List II-82
- 【leetcode刷题笔记】Remove Duplicates from Sorted List
- 【leetcode c++】82 Remove Duplicates from Sorted List II
- leetcode-Remove Duplicates from Sorted List II
- LeetCode – Remove Duplicates from Sorted List II (Java)
- LeetCode 83 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、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 【Java】
- Leetcode-Remove Duplicates from Sorted List II(二级指针)
- leetcode83 Remove Duplicates from Sorted List
- [LeetCode]Merge Two Sorted Lists & Remove Duplicates from Sorted List 两个有序链表合并为一个&删除链表重复元素
- leetcode 83 Remove Duplicates from Sorted List
- leetcode Remove Duplicates from Sorted List
- leetcode - Remove Duplicates from Sorted List
- 【LeetCode-面试算法经典-Java实现】【083-Remove Duplicates from Sorted List(排序的单链表中删除重复的结点)】
- [LeetCode] Remove Duplicates from Sorted List II