-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddTwoNumbers.py
More file actions
36 lines (30 loc) · 758 Bytes
/
Copy pathAddTwoNumbers.py
File metadata and controls
36 lines (30 loc) · 758 Bytes
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
31
32
33
34
35
36
# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def addTwoNumbers(self, l1, l2):
"""
:type l1: ListNode
:type l2: ListNode
:rtype: ListNode
"""
count = 0
total1 = 0
while True:
total1 += l1.val * (10**count)
if l1.next == None:
break
else:
count += 1
l1 = l1.next
return total1
l1 = ListNode(2)
l1.next = ListNode(4)
l1.next.next = ListNode(3)
l2 = ListNode(5)
l2.next = ListNode(6)
l2.next.next = ListNode(4)
solution = Solution()
solution.addTwoNumbers(l1, l2)