二叉树的遍历
代码:
vector<int> path; int sumNumbers(TreeNode *root) {
if (!root)
return ; int sum = ;
path.push_back(root->val); if (!root->left && !root->right) {
for (int i = ; i < path.size(); i++)
sum = sum * + path[i];
}
else {
if (root->left)
sum += sumNumbers(root->left);
if (root->right)
sum += sumNumbers(root->right);
} path.pop_back(); return sum;
}