class Solution {
private:
vector<vector<int>> res;
vector<int> path;
void findPaths(TreeNode* root, vector<int> path, int sum) {
if (!root) return;
sum -= root->val;
path.push_back(root->val);
if (!root->left && !root->right && sum == 0) {
res.push_back(path);
return;
}
findPaths(root->left, path, sum);
findPaths(root->right, path, sum);
}
public:
vector<vector<int>> pathSum(TreeNode* root, int targetSum) {
findPaths(root, path, targetSum);
return res;
}
};