<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) {

        if (num1.size() > num2.size())
            return multiply(num2, num1);

        if (num1 == "0" || num2 == "0")
            return "0";

        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());

        int n1 = num1.size();
        int n2 = num2.size();
        vector<string> mult_res;

        for (int i=0; i<n1; i++)
        {
            int carry = 0;
            string temp = "";
            int dig1 = num1[i] - '0';
            for (int j=0; j<n2; j++)
            {
                int res = dig1 * (num2[j] - '0') + carry;
                int res_dig = res % 10;
                carry = res / 10;
                temp += to_string(res_dig);
            }
            if(carry)
                temp += to_string(carry);

            for (int k=0; k<i; k++)
                temp = "0" + temp;

            mult_res.push_back(temp);
        }

        int max_len = 0;
        int vec_size = mult_res.size();
        for (int i=0; i<vec_size; i++)
            max_len = max(max_len, (int)mult_res[i].size());

        for (int i=0; i<vec_size; i++)
        {
            while (mult_res[i].size() < max_len) 
                mult_res[i] += "0";
        }

        int carry = 0;
        string _res_ = "";

        for (int i=0; i<max_len; i++)
        {
            int res = 0;
            for (int j=0; j<vec_size; j++)
                res += (mult_res[j][i] - '0');

            res += carry;
            int res_dig = res % 10;
            carry = res / 10;
            _res_ = to_string(res_dig) + _res_;
        }

        if (carry)
            _res_ = to_string(carry) + _res_;


        return _res_;
    }
};
29049