Skip to content

Commit 88cce13

Browse files
author
lightmen
committed
add remove-duplicates-from-sorted-list-ii.c
1 parent edb0def commit 88cce13

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* struct ListNode *next;
6+
* };
7+
*/
8+
struct ListNode* deleteDuplicates(struct ListNode* head) {
9+
struct ListNode root;
10+
struct ListNode *prev,*tmp;
11+
int start_val;
12+
int count;
13+
14+
root.next = NULL;
15+
prev = &root;
16+
while(head)
17+
{
18+
start_val = head->val;
19+
count = 1;
20+
while(head->next && head->next->val == start_val){
21+
++count;
22+
head = head->next;
23+
}
24+
tmp = head->next;
25+
if(count == 1){
26+
head->next = prev->next;
27+
prev->next = head;
28+
prev = head;
29+
}
30+
head = tmp;
31+
}
32+
33+
return root.next;
34+
}

0 commit comments

Comments
 (0)