forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0043.cpp
More file actions
32 lines (24 loc) · 853 Bytes
/
0043.cpp
File metadata and controls
32 lines (24 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution {
public:
string multiply(string num1, string num2) {
int siz1 = num1.length();
int siz2 = num2.length();
vector<int> store((siz1 + siz2), 0);
for(int i = siz1 - 1; i >= 0; i--){
for(int j = siz2 - 1; j >= 0; j--){
int mul = (num1[i] - '0') * (num2[j] - '0');
int sum = store[i + j + 1] + mul;
store[i + j] += sum / 10;
store[i + j + 1] = sum % 10;
}
}
string result = "";
for(int i = 0; i < (siz1 + siz2); i++)
if(result.length() != 0 || store[i] != 0)
result += (store[i] + '0');
if(result.length() == 0){
return "0";
}
return result;
}
};