Skip to content

Commit 7ae9250

Browse files
Refine
Signed-off-by: begeekmyfriend <begeekmyfriend@gmail.com>
1 parent f0a827e commit 7ae9250

File tree

2 files changed

+19
-15
lines changed
  • 082_remove_duplicates_from_sorted_list_ii
  • 083_remove_duplicates_from_sorted_list

2 files changed

+19
-15
lines changed

082_remove_duplicates_from_sorted_list_ii/rm_dup.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33

4+
45
struct ListNode {
56
int val;
67
struct ListNode *next;
78
};
89

9-
struct ListNode* deleteDuplicates(struct ListNode* head) {
10+
struct ListNode* deleteDuplicates(struct ListNode* head)
11+
{
1012
struct ListNode dummy;
11-
struct ListNode *p, *next, *prev;
13+
struct ListNode *p, *q, *prev;
1214
prev = &dummy;
1315
dummy.next = head;
14-
p = next = head;
16+
p = q = head;
1517
while (p != NULL) {
16-
while (next != NULL && next->val == p->val) {
17-
next = next->next;
18+
while (q != NULL && q->val == p->val) {
19+
q = q->next;
1820
}
19-
if (p->next == next) {
21+
if (p->next == q) {
2022
prev = p;
2123
} else {
22-
prev->next = next;
24+
prev->next = q;
2325
}
24-
p = next;
26+
p = q;
2527
}
2628
return dummy.next;
2729
}

083_remove_duplicates_from_sorted_list/rm_dup.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33

4+
45
struct ListNode {
56
int val;
67
struct ListNode *next;
78
};
89

9-
struct ListNode* deleteDuplicates(struct ListNode* head) {
10-
struct ListNode *p, *next;
11-
p = next = head;
10+
struct ListNode* deleteDuplicates(struct ListNode* head)
11+
{
12+
struct ListNode *p, *q;
13+
p = q = head;
1214
while (p != NULL) {
13-
while (next != NULL && next->val == p->val) {
14-
next = next->next;
15+
while (q != NULL && q->val == p->val) {
16+
q = q->next;
1517
}
16-
p->next = next;
17-
p = next;
18+
p->next = q;
19+
p = q;
1820
}
1921
return head;
2022
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy