Skip to content

Commit edfaf63

Browse files
Upload From PC
1 parent 35208e3 commit edfaf63

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

LeetCode/2.-Add_Two_Numbers.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
int* addTwoNumbers(int* list1, int* list2){
2+
int *newList, i=0, l1l= sizeof(list1)/4, l2l= sizeof(list2)/4, j, k;
3+
4+
if(l1l > l2l){
5+
newList = (int*)calloc((l1l+1),4);
6+
j= l2l;
7+
k=j;
8+
9+
while(j>0){
10+
newList[i]= list1[i] + list2[i];
11+
if(newList[i] > 9){
12+
newList[i+1]++;
13+
newList[i] -= 10;
14+
}
15+
j--; i++;
16+
}
17+
k= l1l-k;
18+
19+
while(k>0){
20+
newList[i]= list1[i];
21+
i++; k--;
22+
}
23+
}
24+
else{
25+
newList = (int*)calloc((l2l+1),4);
26+
j= l1l;
27+
k=j;
28+
29+
while(j>0){
30+
newList[i]= list1[i] + list2[i];
31+
if(newList[i] > 9){
32+
newList[i+1]++;
33+
newList[i] -= 10;
34+
}
35+
j--; i++;
36+
}
37+
k= l2l-k;
38+
39+
while(k>0){
40+
newList[i]= list2[i];
41+
i++; k--;
42+
}
43+
}
44+
45+
return newList;
46+
}

0 commit comments

Comments
 (0)