```
class Solution {
public:
vector<vector<int>> res;
void helper(TreeNode* root, int sum, vector<int>& path){ //output limit exceeded
if(!root) return;
if(root->val == sum && !root->left && !root->right){
path.push_back(sum);
res.push_back(path);
return;
}
path.push_back(root->val);
helper(root->left,sum-root->val,path);
helper(root->right,sum-root->val,path);
}
vector<vector<int>> pathSum(TreeNode* root, int sum) {
vector<int> path;
helper(root, sum, path);
return res;
}
};
helper(TreeNode* root, int sum, vector<int> path) is ok.
```

Anyone can explain it? thx