FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Leetcode/0002_Add_Two_Numbers.cpp at main · Nothing-avil/Leetcode · GitHub
Nothing-avil
/
Leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
4
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Leetcode
/
0002_Add_Two_Numbers.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (30 loc) · 772 Bytes
Breadcrumbs
Leetcode
/
0002_Add_Two_Numbers.cpp
Copy path
File metadata and controls
30 lines (30 loc) · 772 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
struct
ListNode
*
addTwoNumbers
(
struct
ListNode
* l1,
struct
ListNode
* l2){
struct
ListNode
*
L3
, *l3=(
struct
ListNode
*)
malloc
(
sizeof
(
struct
ListNode
));
L3
=l3;
int
c=
0
;
while
(l1!=
NULL
|| l2!=
NULL
){
int
s=c;
if
(l1!=
NULL
){
s=s+l1->
val
;
l1=l1->
next
;
}
if
(l2!=
NULL
){
s= s + l2->
val
;
l2=l2->
next
;
}
c=s/
10
;
s=s%
10
;
struct
ListNode
*n=(
struct
ListNode
*)
malloc
(
sizeof
(
struct
ListNode
));
n->
val
=s;
n->
next
=
NULL
;
L3
->
next
=n;
L3
=
L3
->
next
;
}
if
(c>
0
){
struct
ListNode
*n=(
struct
ListNode
*)
malloc
(
sizeof
(
struct
ListNode
));
n->
val
=c;
n->
next
=
NULL
;
L3
->
next
=n;
}
return
l3->
next
;
}
Back
|
FazBrowse Home
|
New Git URL