/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<vector<int>> pathSum(TreeNode* root, int sum) {
vector<vector<int>> res = {};
if (root){
if (root->left == NULL && root->right == NULL && root->val == sum){
res.push_back(vector<int> ());
res[res.size()-1].push_back(root->val);
return res;
}
else {
vector<vector<int>> temp = pathSum(root->left, sum-root->val);
for (auto i:temp){
res.push_back(vector<int>());
res[res.size()-1].push_back(root->val);
for (auto j:i) res[res.size()-1].push_back(j);
}
temp = pathSum(root->right, sum-root->val);
for (auto i:temp){
res.push_back(vector<int>());
res[res.size()-1].push_back(root->val);
for (auto j:i) res[res.size()-1].push_back(j);
}
}
}
return res;
}
};