Add Two Numbers 2
Input: (7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 8 -> 0 -> 7# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
v1 = str("")
while l1:
v1 = v1 + str(l1.val)
l1 = l1.next
v2 = ""
while l2:
v2 = v2 + str(l2.val)
l2 = l2.next
v3 = str(int(v1) + int(v2))
head = ListNode(int(v3[0]))
res = head
for i in range(1, len(v3)):
head.next = ListNode(int(v3[i]))
head = head.next
return resLast updated