What's wrong with my code. Why is it falling on some of test cases

google
Tags: #<Tag:0x00007f1827e11928>

#1

My code is here:

void helper(TreeNode* root, vector&res, string s)
{
if(root==NULL)
{
return;
}
if(root->left==NULL && root->right==NULL)
{
s +=(root->val+‘0’);
res.push_back(s);
s.pop_back();
}
s +=(root->val+‘0’);
helper(root->left, res, s);
helper(root->right, res, s);
s.pop_back();
}

int Solution::sumNumbers(TreeNode* A) {

int maxi = 1003;
vector<string> res;
string str="";
helper(A, res, str);
int num=0;
for(int i=0; i<res.size(); i++)
{
    num = (num%maxi + stoi(res[i])%maxi)%maxi;
}
return num;

}


#2

because when u add root to leaf (res[i]) is value is out of range of int so, stoi can’t convert string to int type integer.