Skip to content

Commit f0a827e

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

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

002_add_two_numbers/add_two_numbers.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,20 @@ static struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2)
2020
int last_carry = carry;
2121

2222
if (l1 != NULL) {
23-
if (p == NULL) {
24-
/* p never be NULL */
25-
prev->next = l1;
26-
p = l1;
27-
}
2823
sum += l1->val;
2924
l1 = l1->next;
3025
}
3126

3227
if (l2 != NULL) {
3328
if (p == NULL) {
34-
/* p never be NULL */
29+
/* l2 longer than l1 */
3530
prev->next = l2;
3631
p = l2;
3732
}
3833
sum += l2->val;
3934
l2 = l2->next;
4035
}
41-
36+
4237
sum += last_carry;
4338
carry = sum / 10;
4439
p->val = sum % 10;

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