<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 num_mul_str(char& num, string my_str) {
        string reverse_str = my_str;
        reverse(reverse_str.begin(), reverse_str.end());

        string ans = "";
        int carry = 0;
        int digit = 0;

        for (int i = 0; i < my_str.size(); i++) {
            digit = ( (reverse_str[i] - '0') * (num - '0') + carry ) % 10;
            ans = to_string(digit) + ans;
            carry = ( (reverse_str[i] - '0') * (num - '0') + carry ) / 10;
        }
        if (carry != 0) {
            ans = to_string(carry) + ans;
        }

        return ans;
    };

    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0") {
            return "0";
        }

        int n2 = num2.size();

        vector<string> step_ans(n2, "");
        vector<string> reverse_step_ans(n2, "");
        int max_len = 0;

        for (int i = 0; i < n2; i++ ) {
            string zeros(n2 - i - 1, '0');
            step_ans[i] = num_mul_str(num2[i], num1) + zeros;
            // cout << "step_ans[i]: " << step_ans[i] << endl;
            reverse_step_ans[i] = step_ans[i];
            reverse(reverse_step_ans[i].begin(), reverse_step_ans[i].end());

            if (step_ans[i].size() > max_len) {
                max_len = step_ans[i].size();
            } else {
                continue;
            }
        }

        // for (auto ele : step_ans) {
        //     cout << "step_ans: " << ele << endl;
        // }
        // for (auto ele : reverse_step_ans) {
        //     cout << "reverse_step_ans: " << ele << endl;
        // }

        string ans = "";
        int carry = 0;
        int digit = 0;
        for (int j = 0; j < max_len; j++ ) {
            int intermediate_sum = 0;
            for (int i = 0; i < n2; i++) {
                if (j < step_ans[i].size()) {
                    // cout << "intermediate_sum: " << intermediate_sum << endl;
                    intermediate_sum += reverse_step_ans[i][j] - '0';
                    // cout << "intermediate_sum: " << intermediate_sum << endl;
                    // cout << "reverse_step_ans[i][j]: " << reverse_step_ans[i][j] << endl;
                }
            }
            digit = (intermediate_sum + carry) % 10;
            carry = (intermediate_sum + carry) / 10;
            ans = to_string(digit) + ans;
        }
        if (carry != 0) {
            ans = to_string(carry) + ans;
        }

        return ans;
    }
};
30593