Skip to content

Instantly share code, notes, and snippets.

@gjlmotea
Created April 3, 2020 05:12
Show Gist options
  • Save gjlmotea/49b0f7055d08e71111f53d2ea8ccb737 to your computer and use it in GitHub Desktop.
Save gjlmotea/49b0f7055d08e71111f53d2ea8ccb737 to your computer and use it in GitHub Desktop.
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
list1 = []
list2 = []
while l1:
list1.append(l1.val)
l1 = l1.next
while l2:
list2.append(l2.val)
l2 = l2.next
list1.reverse()
list2.reverse()
num1 = 0
num2 = 0
for i in list1:
num1 = num1 * 10 + i
for i in list2:
num2 = num2 * 10 + i
ans = num1 + num2
ans = list(str(ans))
ans.reverse()
head = ListNode
l3 = head
for i in ans:
l3.next = ListNode(i)
l3 = l3.next
return head.next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment