```
class Solution {
vector<vector<int>> res;
vector<int> item;
public:
vector<vector<int>> pathSum(TreeNode* root, int sum) {
if(root == NULL) return res;
if (root->left == NULL && root->right == NULL)
{
if (root->val == sum)
{
item.push_back(root->val);
res.push_back(item);
item.pop_back();
}
return res;
}
item.push_back(root->val);
if (root->left) pathSum(root->left, sum - root->val);
if (root->right) pathSum(root->right, sum - root->val);
item.pop_back();
return res;
}
};
```