meteorlxy / vssue

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

[Feature Request] #175

Closed Jing65 closed 4 days ago

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