class Solution {
public:
vector<vector<int>> ans;
vector<int> path;
vector<vector<int>> pathSum(TreeNode* root, int targetSum) {
if(root) dfs(root,targetSum);
return ans;
}
void dfs(TreeNode* root,int sum){
path.push_back(root->val);
sum-=root->val;
if(!root->left&&!root->right){
if(!sum){ans.push_back(path);}
}
if(root->left) dfs(root->left,sum);
if(root->right) dfs(root->right,sum);
path.pop_back();
}
};
10-28
09-08
1096
09-13
995