leetCode415

class Solution {
public:
    string addStrings(string num1, string num2) {
        string s3;
        int len1 = num1.size();
        int len2 = num2.size();
        int c = 0;
        while(len1!=0 || len2!=0)
        {
            if(len1!=0)
            {
                c+= num1[len1-1]-'0';
                len1--;
            }
            if(len2!=0)
            {
                c+= num2[len2-1]-'0';
                len2--;
            }
            s3.push_back('0'+c%10);
            c/=10;
        }
        if(c) s3.push_back('0'+c);
        reverse(s3.begin(),s3.end());
        return s3;
    }
};

 

你可能感兴趣的:(leetcode)