```
class Solution {
public:
int sumNumbers(TreeNode* root) {
int result = 0;
helper(root, 0, result);
return result;
}
void helper(TreeNode* node, int path, int &result) {
if (NULL == node) return;
path += node->val;
if (NULL == node->left && NULL == node->right) result += path;
else {
path *= 10;
helper(node->left, path, result);
helper(node->right, path, result);
}
}
};
```