Python Straightforward


  • 0
        def multiply(self, num1, num2):
            """
            :type num1: str
            :type num2: str
            :rtype: str
            """
            if num1 == "0" or num2 == "0": return "0"
            short = num1 if len(num1) < len(num2) else num2
            lng = num2 if len(num2) > len(num1) else num1
            res, digit = 0, 1
            for s in range(len(short)-1,-1,-1):
                num, lDigit = int(short[s]) * digit, 1
                for l in range(len(lng)-1,-1,-1):
                    res += num * int(lng[l]) * lDigit
                    lDigit *= 10
                digit *= 10
            return str(res)    
    

Log in to reply
 

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