class Solution { public: vector<int>v; int num; int sumNumbers(TreeNode *root) { num=0; v.clear(); sum(root); int sum=0; for(int i=0;i<v.size();i++) sum+=v[i]; return sum; } void sum(TreeNode *root) { if(root==NULL) return; if(root!=NULL) { num=num*10+root->val; if(root->left==NULL&&root->right==NULL) { v.push_back(num); } if(root->left)sum(root->left); if(root->right)sum(root->right); num=(num-root->val)/10; } } };