forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
30 lines (30 loc) · 706 Bytes
/
solution.cpp
File metadata and controls
30 lines (30 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* 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)
{
ListNode** curNext = &head;
ListNode* cur = head;
while(NULL != cur)
{
ListNode* temp = cur;
while(NULL != cur->next && cur->next->val == cur->val)
cur = cur->next;
if(cur == temp)
{
*curNext = temp;
curNext = &(*curNext)->next;
}
cur = cur->next;
}
*curNext = NULL;
return head;
}
};