-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path113.h
More file actions
44 lines (41 loc) · 1.03 KB
/
113.h
File metadata and controls
44 lines (41 loc) · 1.03 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Definition of ListNode
* class ListNode {
* public:
* int val;
* ListNode *next;
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
public:
/*
* @param head: head is the head of the linked list
* @return: head of the linked list
*/
ListNode * deleteDuplicates(ListNode * head) {
// write your code here
if(head == nullptr || head->next == nullptr) return head;
ListNode dummyhead(0);
ListNode *cur = &dummyhead;
while(head != nullptr){
if(head->next != nullptr && head->next->val == head->val){
int val = head->val;
while(head != nullptr && head->val == val){
head = head->next;
}
continue;
}
else{
cur->next = head;
cur = head;
}
head = head->next;
}
cur->next = nullptr;
return dummyhead.next;
}
};