meteorlxy / vssue

:mailbox: A Vue-powered Issue-based Comment Plugin
https://vssue.js.org
MIT License
775 stars 105 forks source link

[Feature Request] #175

Open Jing65 opened 3 months ago

Jing65 commented 3 months 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;
}