Python O(n+m)


  • 0
    R

    Don't know if this satisfies the description... accepted though.

    def multiply(self, num1, num2):
            d = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}
            n1 = num1[::-1]
            n2 = num2[::-1]
            sum1 = 0
            sum2 = 0
            for i in range(len(n1)):
                sum1 += d[n1[i]]*(10**i)
            for i in range(len(n2)):
                sum2 += d[n2[i]]*(10**i)
            return str(sum1*sum2)
    

Log in to reply
 

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