Easy CPP solution....have a look


#1

void form_and_add(TreeNode* ptr,int curr,int& sum)
{
if(ptr==NULL)
return;

curr=((curr*10)+(ptr->val))%1003;
if(ptr->left==NULL && ptr->right==NULL)
{
    sum+=curr%1003;
    return;
    // terminated at leaf
}

form_and_add(ptr->left,curr,sum);
form_and_add(ptr->right,curr,sum);

}
int Solution::sumNumbers(TreeNode* A) {
int sum=0;
int curr=0;
form_and_add(A,curr,sum);
return sum%1003;
}