Python: Deconstruct to Lists then add

  • 0

    This code took me a lot longer than it should of, but I finished it. Let me know what you think.

    class Solution(object):
        def addTwoNumbers(self, l1, l2):
            list1 = []
            list2 = []
            while l1:
                l1 =
            while l2:
                l2 =
            n1,n2= "".join(list1), "".join(list2)
            n = int(n1)+int(n2)
            new_values = map(lambda x:int(x),str(n))
            l = ListNode(new_values[0])
            head = l                #keep track of the head and where we going
            for value in new_values[1:]:
       = ListNode(None)
            return head

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.