<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:
    int ctoi(char c) {
        switch (c) {
            case '0':
                return 0;
            case '1':
                return 1;
            case '2':
                return 2;
            case '3':
                return 3;
            case '4':
                return 4;
            case '5':
                return 5;
            case '6':
                return 6;
            case '7':
                return 7;
            case '8':
                return 8;
            case '9':
                return 9;
            default:
                return-1;
        }

    }
    vector<int> string_to_arr(string s) {
        vector<int> result;
        for (size_t i = 0; i < s.length(); i++) {
            result.push_back(ctoi(s[i]));
        }
        return result;
    }

    vector<int> multi_arr(vector<int> a, int b) {
        if (b == 0)
            return {0};
            
        vector<int> result;
        int n = a.size() - 1;
        int temp = 0;
        int carry = 0;
        for (size_t i = 0; i < a.size(); i++) {
            temp = a[n-i]*b;
            if((temp + carry) >= 10)
                result.push_back((temp + carry)%10);
            else
                result.push_back(temp + carry);
            carry = (temp + carry)/10;
        }
        if (carry != 0)
            result.push_back(carry);
        reverse(result.begin(), result.end());

        while (result.size() != 1 && result[0] == 0)
            result.erase(result.begin());
        
        return result;
    }

    vector<int> multi_2arr(vector<int> a, vector<int> b) {
        int size_a = a.size() - 1;
        int size_b = b.size() - 1;
        if (size_a < size_b){
            swap(a, b);
            swap(size_a, size_b);
        }

        if (a.size() == 1 || b.size() == 1)
            return multi_arr(a, b[0]);

        vector<int> result{0};

        vector<vector<int>> temp;
        for (size_t i = 0; i <= size_b; i++) {
            temp.push_back(multi_arr(a, b[size_b - i]));
        }
        int carry = 0;
        int num_round = a.size()*b.size();

        for (int i = 0; i < num_round; i++) {

            for (int j = 0; j < temp.size(); j++) {
                int size_temp = temp[j].size() - 1;
                
                if (size_temp - (i - j) >= 0 && i - j >= 0)
                    result[i] += temp[j][size_temp - (i - j)];
            }
            if (result[i] >= 10) {
                carry = result[i]/10;
                result[i] %= 10;
                result.push_back(carry);
            }
            else
                result.push_back(0);
        }
        reverse(result.begin(), result.end());
        while (!result.empty() && result[0] == 0)
            result.erase(result.begin());

        return result;
    }


    string int_to_string(int a) {
       if (a == 0)
            return "0";
        int temp = 0;
        string result = "";
        while (a != 0) {
            temp = a - 10*(a/10);
            result += to_string(temp);
            a /= 10;
        }
        reverse(result.begin(), result.end());
        return result;
    }

    string multiply(string num1, string num2) {
        vector<int> a = string_to_arr(num1);
        vector<int> b = string_to_arr(num2);
        vector<int> result = multi_2arr(a, b);
        string result_str = "";
        for (size_t i = 0; i < result.size(); i++) {
            result_str += int_to_string(result[i]);
        }
        return result_str;
    }
};
22256