class Solution {
public:
/*
*
* @param root TreeNode类
* @param sum int整型
* @return int整型vector<vector<>>
*/
void DFS(vector<vector<int>>& ans,vector<int> res,TreeNode</int></int>
root,int sum)
{
if(!root) return ;
res.push_back(root->val);
if(root->val == sum && !root->left && !root->right)
ans.push_back(res);
DFS(ans,res,root->left,sum-root->val);
DFS(ans,res,root->right,sum-root->val);
}

vector<vector<int> > pathSum(TreeNode* root, int sum) {
    vector<vector<int>> ans;
    vector<int> res;
    DFS(ans,res,root,sum);
    return ans;
}

};