//剑指offer:搜索一个二叉树,并且把和为expectNumber的路径上的值输出
void funcPath(TreeNode* root, int expectNumber, int currentSum, vector<int> v, vector<vector<int> >& res) {
currentSum += root->val;
v.push_back(root->val);
if (currentSum == expectNumber && root->left == nullptr && root->right == nullptr) {
res.push_back(v);
}
if (root->left != nullptr)
funcPath(root->left, expectNumber, currentSum, v, res);
if (root->right != nullptr)
funcPath(root->right, expectNumber, currentSum, v, res);
v.pop_back();
}
剑指offer:输出二叉树和为某一值的所有路径
最新推荐文章于 2022-05-20 08:00:00 发布