Created
April 3, 2020 05:12
-
-
Save gjlmotea/49b0f7055d08e71111f53d2ea8ccb737 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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