/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @return int整型
     */
    int sumNumbers(TreeNode* root,int x=0) {
        if(root==nullptr){
            return 0;
        }
        int ans=0;
        x+=root->val;
        if(root->left==nullptr&&root->right==nullptr){
            return x;
        }
        ans+=sumNumbers(root->left,x*10);
        ans+=sumNumbers(root->right,x*10);
        return ans;
    }
};