Closed Jing65 closed 4 days ago
257.贴个二叉树路径的迭代写法 void findPath(TreeNode* cur, int targetSum,vector<vector>& ans,vector path) { if(cur == nullptr) return;
path.push_back(cur->val); if(cur->val == targetSum&&cur->left == nullptr&&cur->right==nullptr) { ans.push_back(path); return; } findPath(cur->left,targetSum-cur->val,ans,path); findPath(cur->right,targetSum-cur->val,ans,path); // return; } vector<vector<int>> pathSum(TreeNode* root, int targetSum) { vector<vector<int>> ans; vector<int> path; if(root == nullptr) return ans; findPath(root,targetSum,ans,path); return ans; }
257.贴个二叉树路径的迭代写法 void findPath(TreeNode* cur, int targetSum,vector<vector>& ans,vector path)
{
if(cur == nullptr) return;