class Solution {
public:
vector<vector<int>> pathSum(TreeNode* root, int target) {
vector<vector<int>> res;
vector<int> path;
findPath(root, target, res, path);
return res;
}
void findPath(TreeNode* root, int target, vector<vector<int>>& res, vector<int>& path){
if (root == nullptr) return;
target -= root->val;
path.push_back(root->val);
if (!target && !root->left && !root->right) res.push_back(path);
if (root->left) findPath(root->left, target, res, path);
if (root->right) findPath(root->right, target, res, path);
path.pop_back();
}
};