Skip to content

Commit

Permalink
Create 029 Add Two Numbers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
atharv-patil authored Jun 17, 2023
1 parent dcba15d commit 7d15dec
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 029 Add Two Numbers.py
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

0 comments on commit 7d15dec

Please sign in to comment.