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