Given two numbers represented as strings, return multiplication of the numbers as a string.
Note:
- The numbers can be arbitrarily large and are non-negative.
- Converting the input string to integer is NOT allowed.
- You should NOT use internal library such as BigInteger.
兩個 string 來做相乘的動作,基本上就是把乘法的步驟做分解
想法可以用以下圖來解釋(參考資料)
- 首先,m 位數乘上 n 位數,答案最多就是 m+n 位數
- 和一般算乘法一樣,先把每個位元相乘的結果算出來,然後根據位置相加起來
- 接著進行求餘數,進位相加的動作
- 記得要把多餘的前置0給拿掉
沒有留言:
張貼留言