class Solution {
public static String multiply(String num1, String num2) {
if(num1.equals("0") || num2.equals("0"))
return "0";
StringBuilder result = new StringBuilder();
char[] c1 = num1.toCharArray();
char[] c2 = num2.toCharArray();
int[] res = new int[c1.length + c2.length];
for(int i = c2.length - 1; i >= 0; i --) {
int lost = 0;
int addNum = 0;
for(int j = c1.length - 1; j >= 0; j--) {
int temp1 = (c1[j] - '0') * (c2[i] - '0') + addNum;
addNum = temp1 / 10;
temp1 = temp1 % 10;
int temp2 = res[i + j + 1] + lost + temp1;
res[i + j + 1] = (temp2 % 10);
lost = temp2 / 10;
}
res[i] += (lost + addNum);
}
for(int i = 0; i < res.length; i ++) {
result.append(res[i]);
}
if(result.charAt(0) == '0')
return result.substring(1,result.length());
return result.toString();
}
}