![这里写图片描述](https://img-blog.csdn.net/20161102153233250)
class Solution {
public:
vector<vector<int>> ans;
vector<int>tmp;
vector<vector<int>> pathSum(TreeNode* root, int sum) {
if (root == NULL)
return ans;
dfs(root, sum);
return ans;
}
void dfs(TreeNode* current, int sum)
{
tmp.push_back(current->val);
if (current->left == NULL && current->right == NULL && sum==current->val )
{
ans.push_back(tmp);
tmp.pop_back();
return;
}
if (current->left)
dfs(current->left, sum-current->val);
if (current->right)
dfs(current->right, sum-current->val);
tmp.pop_back();
}
};
![这里写图片描述](https://img-blog.csdn.net/20161104182039984)