题目:
题解:
func multiply(num1 string, num2 string) string {if num1 == "0" || num2 == "0" {return "0"}m, n := len(num1), len(num2)ansArr := make([]int, m + n)for i := m - 1; i >= 0; i-- {x := int(num1[i]) - '0'for j := n - 1; j >= 0; j-- {y := int(num2[j] - '0')ansArr[i + j + 1] += x * y}}for i := m + n - 1; i > 0; i-- {ansArr[i - 1] += ansArr[i] / 10ansArr[i] %= 10}ans := ""idx := 0if ansArr[0] == 0 {idx = 1}for ; idx < m + n; idx++ {ans += strconv.Itoa(ansArr[idx])}return ans
}