大数乘法..写的有点复杂...
class Solution { public: string multiply(string num1, string num2) { int size1 = num1.size(); int size2 = num2.size(); vector<int> n1(size1,0); vector<int> n2(size2,0); vector<int> n3(size1+size2+2 , 0); reverse(num1.begin() , num1.end()); reverse(num2.begin() , num2.end()); for(int i = 0 ; i < size1 ; i++) { n1[i] = num1[i] - '0'; } for(int i = 0 ; i < size2 ; i++) { n2[i] = num2[i] - '0'; } for(int i = 0 ; i < size1 ; i++) { for(int j = 0 ; j < size2 ; j ++) { n3[j+i] += n1[i] * n2[j]; n3[j+i+1] += n3[j+i] / 10; n3[j+i] %= 10; } } stringstream ss; int rightmost = size1 + size2; while(rightmost >= 0 && n3[rightmost] == 0) rightmost --; for(int i = 0 ; i <= rightmost ; i ++) ss << n3[i]; string ans = ss.str(); reverse(ans.begin() , ans.end()); if(ans == "") return "0"; return ans; } };