Sum Root to Leaf Numbers Time : Space : 12345678910111213141516171819202122232425/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */const int mod = 1003;void helper(TreeNode* A, int& res, long long now) { if(!A) return; now = (now * 10 + A->val) % mod; if(!A->left and !A->right) res = (res + now) % mod; else { helper(A->left,res,now); helper(A->right,res,now); }}int Solution::sumNumbers(TreeNode* A) { int res = 0; helper(A,res,0); return res;}