class Solution { public: int sumNumbers(TreeNode *root) { int sum = 0; if (root == NULL) return sum; return pre(root, sum); } int pre(TreeNode *root, int sum) { if (root == NULL)return 0; sum = sum * 10 + root->val; if (root->left == NULL&&root->right == NULL){ return sum; } return pre(root->left, sum) + pre(root->right, sum); } };