<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=="0" || num2=="0") return "0";
        string finalans="";
        if(num1.length()>=num2.length())
        {
            for(int i=num2.length()-1;i>=0;i--)
            {
                int carry=0;
                string ans="";
               for(int j=num1.length()-1;j>=0;j--)
               {
                int temp=(num1[j]-'0')*(num2[i]-'0')+carry;
                carry=temp/10;
                int num=temp%10;
                ans+=(num+'0');
               }
               if(carry!=0) ans+=(carry+'0');
               cout<<ans<<" ";
               for(int t=0;t<num2.length()-1-i;t++)
               {
                ans='0'+ans;
               }
               cout<<ans<<" ";
               if(finalans=="")
               {
                finalans=ans;
               }
               else{
                int y=0;
                int carry1=0;
                while(y<ans.size())
                {
                    int m=ans[y]-'0';
                    if(y<finalans.size())
                    {
                    int t=finalans[y]-'0';
                    int total=t+m+carry1;
                    carry1=total/10;
                    total%=10;
                    ans[y]=(total+'0');
                    }
                    else{
                        m=m+carry1;
                        carry1=m/10;
                        m%=10;
                        ans[y]=(m+'0');
                    }
                   y++;
                }
                if(carry1) ans+=(carry1+'0');
                finalans=ans;
                
               }

            }
        }
        else{
             string temp=num1;
             num1=num2;
             num2=temp;
             for(int i=num2.length()-1;i>=0;i--)
            {
                int carry=0;
                string ans="";
               for(int j=num1.length()-1;j>=0;j--)
               {
                int temp=(num1[j]-'0')*(num2[i]-'0')+carry;
                carry=temp/10;
                int num=temp%10;
                ans+=(num+'0');
               }
               if(carry!=0) ans+=(carry+'0');
               for(int t=0;t<num2.length()-1-i;t++)
               {
                ans='0'+ans;
               }
               if(finalans=="")
               {
                finalans=ans;
               }
               else{
                int y=0;
                int carry1=0;
                while(y<ans.size())
                {
                    int m=ans[y]-'0';
                    if(y<finalans.size())
                    {
                    int t=finalans[y]-'0';
                    int total=t+m+carry1;
                    carry1=total/10;
                    total%=10;
                    ans[y]=(total+'0');
                    }
                    else{
                        m=m+carry1;
                        carry1=m/10;
                        m%=10;
                        ans[y]=(m+'0');
                    }
                   y++;
                }
                if(carry1) ans+=(carry1+'0');
                finalans=ans;
                
               }

            }
        }
    reverse(finalans.begin(),finalans.end());
    return finalans;
    }
};
24726