File tree Expand file tree Collapse file tree 2 files changed +19
-15
lines changed
082_remove_duplicates_from_sorted_list_ii
083_remove_duplicates_from_sorted_list Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Original file line number Diff line number Diff line change 11#include <stdio.h>
22#include <stdlib.h>
33
4+
45struct 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}
Original file line number Diff line number Diff line change 11#include <stdio.h>
22#include <stdlib.h>
33
4+
45struct 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}
You can’t perform that action at this time.
0 commit comments