Multiply Strings my version

mail@pastecode.io avatar
unknown
python
a year ago
627 B
2
Indexable
Never
class Solution:
    def multiply(self, num1: str, num2: str) -> str:
        if num1 == "0" or num2 == "0":
            return "0"
        total = 0
        outterOffset = 1
        l, r = len(num1) - 1, len(num2) - 1
        for j in range(len(num2) - 1, -1, -1):
            rn = ord(num2[j]) - ord('0')
            curSum = 0
            offset = 1
            for i in range(len(num1) -1, -1, -1):
                ln = ord(num1[i]) - ord('0')
                curSum += rn * ln * offset
                offset *= 10
            total += curSum * outterOffset
            outterOffset *= 10
        
        return str(total)