-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathp082.c
49 lines (49 loc) · 1.29 KB
/
p082.c
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
45
46
47
48
49
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* deleteDuplicates(struct ListNode* head) {
struct ListNode *tmphead = (struct ListNode*)malloc(sizeof(struct ListNode));
struct ListNode *cur, *next;
tmphead->next = head;
cur = tmphead;
next = head;
while (next != NULL)
{
if (next->next == NULL)
{
break;
}
else if (next->val != next->next->val)
{
cur = next;
next = next->next;
}
else
{
while (true)
{
while (next->next != NULL && next->val == next->next->val)
{
next = next->next;
}
if (next->next != NULL && next->next->next != NULL && next->next->val == next->next->next->val)
{
next = next->next;
}
else
{
break;
}
}
cur->next = next->next;
cur = cur->next;
if (cur == NULL || cur->next == NULL) break;
else next = cur->next;
}
}
return tmphead->next;
}