试题地址:添加链接描述
class Solution {
public:
vector<vector<int>> res;
vector<vector<int> > FindPath(TreeNode* root,int expectNumber) {
vector<int> vi;
if (root!= nullptr)
getresult(root, vi, expectNumber);
return res;
}
void getresult(TreeNode* root, vector<int> vi, int expectNumber)
{
vi.push_back(root->val);
if (expectNumber - root->val < 0)
return;
if (root->left!= nullptr)
getresult(root->left, vi, expectNumber - root->val);
if (root->right!= nullptr)
getresult(root->right, vi, expectNumber - root->val);
if (root->left == nullptr && root->right== nullptr && expectNumber - root->val == 0)
res.push_back(vi);
}
};