Add Two Numbers II LeetCode solution in Python
1class Solution:2def addTwoNumbers(3self, l1: Optional[ListNode], l2: Optional[ListNode]4) -> Optional[ListNode]:5def number(head):6ans = ""7while head:8ans += str(head.val)9head = head.next10return int(ans)1112temp = dummy = ListNode(0)13for i in str(number(l1) + number(l2)):14temp.next = ListNode(i)15temp = temp.next16return dummy.next