<p>Given two non-negative integers <code>num1</code> and <code>num2</code> represented as strings, return the product of <code>num1</code> and <code>num2</code>, also represented as a string.</p>

<p><strong>Note:</strong>&nbsp;You must not use any built-in BigInteger library or convert the inputs to integer directly.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> num1 = "2", num2 = "3"
<strong>Output:</strong> "6"
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> num1 = "123", num2 = "456"
<strong>Output:</strong> "56088"
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= num1.length, num2.length &lt;= 200</code></li>
	<li><code>num1</code> and <code>num2</code> consist of digits only.</li>
	<li>Both <code>num1</code> and <code>num2</code>&nbsp;do not contain any leading zero, except the number <code>0</code> itself.</li>
</ul>

class Solution {
public:
    string multiply(string num1, string num2) {
        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());
        vector<string> temp;
        for(int i = 0; i < num1.size(); i++){
            string curr;
            for(int j = 0; j < i; j++){
                curr.push_back('0');
            }
            curr += mul(num1[i]-'0', num2);
            for(auto x : curr){
                if(x != '0'){
                    temp.push_back(curr);
                    break;
                }
            }
            temp.push_back("0");
        }
        string ans = temp[0];
        for(int i = 1; i < temp.size(); i++){
            ans = add(ans, temp[i]);
        }
        reverse(ans.begin(), ans.end());
        return ans;
    }
private:
    string add(string a, string b){
        string res = "";
        int i = 0;
        int j = 0;
        int car = 0;
        while(i < a.size() && j < b.size()){
            int curr = a[i] - '0';
            curr+=b[i] - '0';
            curr+=car;
            car = curr/10;
            curr = curr%10;
            res.push_back(curr+'0');
            i++;
            j++;
        }
        while(i < a.size()){
            int curr = a[i] - '0';
            curr+=car;
            car = curr/10;
            curr = curr%10;
            res.push_back(curr+'0');
            i++;
        }
        while(j < b.size()){
            int curr = b[j] - '0';
            curr+=car;
            car = curr/10;
            curr = curr%10;
            res.push_back(curr+'0');
            j++;
        }
        if(car!=0){
            res.push_back(car+'0');
        }
        return res;
    }

    string mul(int x, string s){
        if(x == 0)return string(1,0+'0');
        if(s == "0") return s;
        string res = "";
        int car = 0;
        for(auto c : s){
            int curr = x * (c-'0');
            curr+=car;
            car = curr/10;
            curr = curr % 10;
            res.push_back(curr+'0');
        }
        if(car != 0){
            res.push_back(car+'0');
        }
        return res;
    }
};
19786