<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 adder(string ans, string temp) {
        // 2sum of strings logic
        int n= ans.length()-1;
        int m= temp.length()-1;
        if(m>n) return adder(temp, ans);
        if(m == 0) return ans; //this optimize when one is empty
        int carry = 0;
        while(m>=0) {
            int sum = (temp[m]-'0') + (ans[n]-'0') + carry;
            ans[n] = (char)(sum%10) + '0';
            carry = sum/10;
            n--;m--;
        }
        if(carry>0) { // left out carry
            // adding at front
            // adding in number: (num becames 9 + 1) or (nums)
            if(n<0) ans= (char)((carry) + '0') + ans; 
            else if(ans[n] == '9') {
                ans[n] = '0';
                if(n-1<0) ans = '1' + ans; 
                else ans[n-1] += 1;
            }
            else ans[n] += carry;
        }
        return ans;
    }

    string multiply(string num1, string num2) {
        if(num1.length() < num2.length()) return multiply(num2, num1); // num1 must be bigger
        if(num1[0] == '0' || num2[0] == '0') return "0"; // constraint no leading zeros except num = 0.
        
        int n= num1.length();
        int m= num2.length();
        int j= m-1;
        string ans= "";

        while(j>=0) {
            int i= n-1;
            int carry= 0;
            string temp= "";
            while(i>=0) {
                int pro = (num1[i]-'0') * (num2[j]-'0') + carry;
                int dig = pro%10;
                temp= (char)(dig + '0') + temp;
                carry = pro/10;
                i--;
            }
            if (carry>0) temp = (char)(carry + '0') + temp; //left out carry
            for(int zeros=0; zeros<m-j-1; zeros++) { // adding zeros
                temp+= '0';
            }
            cout<< temp << " + " << ans << " = ";
            ans= adder(temp, ans);   
            cout<< ans << endl;  
            j--;
        }
        return ans;
    }
};
32136