Skip to content

Commit 11d3479

Browse files
committed
Time: 12 ms (47.66%), Space: 11.7 MB (6.02%) - LeetHub
1 parent 25222d4 commit 11d3479

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode() : val(0), next(nullptr) {}
7+
* ListNode(int x) : val(x), next(nullptr) {}
8+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
9+
* };
10+
*/
11+
typedef struct ListNode node;
12+
class Solution {
13+
public:
14+
ListNode* deleteDuplicates(ListNode* head) {
15+
if(head == NULL or head->next == NULL)
16+
return head;
17+
18+
node* curr = head;
19+
while(curr->next != NULL){
20+
if(curr->val == curr->next->val){
21+
node* t = curr->next;
22+
curr->next = t->next;
23+
// curr = curr->next;
24+
delete(t);
25+
}else{
26+
curr = curr->next;
27+
}
28+
}
29+
30+
return head;
31+
}
32+
};

0 commit comments

Comments
 (0)