Very easy to understand Python solution


  • 3
    class Solution(object):
        def addStrings(self, num1, num2):
            def additionStrings(num1, num2, carry):
                if not num1 and not num2: 
                    if carry: res.append(carry)
                    return
                a, b = num1.pop() if num1 else 0, num2.pop() if num2 else 0
                carry, digit = divmod(a + b + carry, 10)
                res.append(digit)
                additionStrings(num1, num2, carry)
            
            res = []
            additionStrings([int(c) for c in num1], 
                            [int(c) for c in num2],
                            0)
            
            return "".join([str(num) for num in res[::-1]])
    

  • 0
    C
    This post is deleted!

Log in to reply
 

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