Simple Python Solution O(num1+num2)


  • 0
    L

    Problem said we couldn't convert to int, but didn't say we can't convert from int to str ;)

    class Solution(object):
        def addStrings(self, num1, num2):
            """
            :type num1: str
            :type num2: str
            :rtype: str
            """
            def convert(c): 
                return ord(c)-ord('0')
            x1=x2=0    
            for i in num1:
                x1=x1*10+ convert(i)
            for j in num2:
                x2=x2*10+convert(j)
            x=x1+x2
            return str(x)
    

Log in to reply
 

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