class Solution {
public:
vector<vector<int>> res;
vector<int> path;
void dfs(TreeNode* root, int sum,int t)
{
t+=root->val;
path.push_back(root->val);
if(root->left)
dfs(root->left,sum,t);
if(root->right)
dfs(root->right,sum,t);
if(!root->left&&!root->right&&sum==t) res.push_back(path);
t-=root->val;
path.pop_back();
}
vector<vector<int>> findPath(TreeNode* root, int sum) {
if(!root) return res;
dfs(root,sum,0);
return res;
}
};
标签:right,res,sum,路径,dfs,二叉树,path,root,一值
From: https://www.cnblogs.com/tangxibomb/p/17278126.html