-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcba15d
commit 7d15dec
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class Node: | ||
def __init__(self, data=0, next=None): | ||
self.data = data | ||
self.next = next | ||
|
||
|
||
# Don't change the code above. | ||
|
||
|
||
def addTwoNumbers(l1: Node, l2: Node) -> Node: | ||
main = Node(0) | ||
a = main | ||
s = '' | ||
while l1: | ||
s += str(l1.data) | ||
l1 = l1.next | ||
s = s[::-1] | ||
|
||
ss = '' | ||
while l2: | ||
ss+=str(l2.data) | ||
l2 = l2.next | ||
ss = ss[::-1] | ||
|
||
sss = list(str(int(s)+int(ss)))[::-1] | ||
n = len(sss) | ||
i = 0 | ||
|
||
while i<n: | ||
a.next = Node(sss[i]) | ||
a = a.next | ||
i+=1 | ||
return main.next |