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.
大数的乘法问题,运用乘法规则就好了。
1 class Solution { 2 public: 3 string multiply(string num1, string num2) { 4 if(num1=="0" || num2=="0") return "0"; 5 string result; 6 int len1=num1.length(); 7 int len2=num2.length(); 8 int len=len1+len2; 9 int* n1=new int[len1];10 int* n2=new int[len2];11 int* multi=new int[len];12 for(int i=0;i=0;i--)39 {40 if(multi[i]!=0)41 {42 first_nozero=i;43 break;44 }45 }46 for(int i=first_nozero;i>=0;i--)47 {48 result+=char(multi[i]+'0');49 }50 delete []n1;51 delete []n2;52 delete []multi;53 54 return result;55 }56 };