Skip to content

Commit 3c6912e

Browse files
committed
Time: 94 ms (47.67%), Space: 13.9 MB (97.35%) - LeetHub
1 parent f3b979c commit 3c6912e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution:
7+
def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:
8+
l3=ListNode(0)
9+
h3=l3
10+
c=0
11+
while(l1 or l2 or c):
12+
if l1:
13+
c+=l1.val
14+
l1=l1.next
15+
if l2:
16+
c+=l2.val
17+
l2=l2.next
18+
l3.val=c%10
19+
c=c//10
20+
if l1 or l2 or c:
21+
l3.next=ListNode(0)
22+
l3=l3.next
23+
return h3
24+

0 commit comments

Comments
 (0)