Add Two Numbers II LeetCode solution in Python

1
class Solution:
2
def addTwoNumbers(
3
self, l1: Optional[ListNode], l2: Optional[ListNode]
4
) -> Optional[ListNode]:
5
def number(head):
6
ans = ""
7
while head:
8
ans += str(head.val)
9
head = head.next
10
return int(ans)
11

12
temp = dummy = ListNode(0)
13
for i in str(number(l1) + number(l2)):
14
temp.next = ListNode(i)
15
temp = temp.next
16
return dummy.next

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0