Welcome to LeetCode Discuss.  Please read the FAQ to help yourself making the best use of Discuss.
Ask a Question
Back to Problem

Welcome to LeetCode Discuss.

This is a place to ask questions related to only OJ problems.

Please read the FAQ to help yourself making the best use of Discuss.

Why Internal Error in this code?

0 votes
74 views
class Solution {
public:
    string multiply(string num1, string num2) {
        int m=num1.size();
        int n=num2.size();
        int i,j,sum,carry=0,temp=m+n-1,k=0,a,b;
        string s;
        for(i=0;i<=temp;i++)
        s+='0';
        for(i=m-1;i>=0;i--)
        {
            a=num1[i]-'0';
            sum=0;
            carry=0;
            k=temp;
            for(j=n-1;j>=0;j--)
            {
                b=num2[j]-'0';
                sum=(a*b+carry)%10;
                carry=(a*b+carry)/10;
                s[k]=sum+s[k];
                k--;
            }
            s[k]=s[k]+carry;
            temp--;
        }
        while(s[i]=='0')
        {
            s.erase(s.begin()+i);
            i++;
        }
        return s;
    }
};
asked Dec 23, 2013 in Multiply Strings by ANMOLDHURIA (210 points)

This had been fixed, please try again now.

Please log in or register to answer this question.


...