05 2024 档案
摘要:https://leetcode.cn/problems/combination-sum-ii/description/ class Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path =
阅读全文
摘要:https://leetcode.cn/problems/combination-sum/description/ 两种搜索思路 一种是选或不选,搜索树是一颗二叉树另一种是选哪个数,是一个n叉树 二叉 class Solution { List<List<Integer>> res = new Ar
阅读全文
摘要:https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/description/ 要点是分割左右区间,并且分割时需要注意left和right相加可能会超过int,但是本题不需要 class Solution {
阅读全文
摘要:https://leetcode.cn/problems/trim-a-binary-search-tree/description/ 要点是区分在区间左边还是右边,在区间左边那么右子树也还有必要去查找删除,右边同理,返回的是删除后新树的根节点 要注意函数要实现单层逻辑和完成闭环语义 class S
阅读全文
摘要:https://leetcode.cn/problems/delete-node-in-a-bst/ 要点是确定函数语义,单层递归逻辑,确定好有返回值的这种写法,分析出5种情况,递归的时候接收好递归的返回的新树的根节点即可 class Solution { // 函数语义(单层递归逻辑):查找要删除
阅读全文
摘要:https://leetcode.cn/problems/insert-into-a-binary-search-tree/ 推荐使用没有返回值的方法,因为比较好想233 递归法: class Solution { public: TreeNode* pre=nullptr; TreeNode* i
阅读全文
摘要:https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-search-tree/ 明确函数的返回值和参数,返回最近公共祖先,没有就返回null 单层递归逻辑是:若按搜索树条件,递归左子树未查询到,递归右子树也未查询到,那么意味着
阅读全文
摘要:https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-tree/description/ 要点是后序遍历,这样就可以从树底开始搜索,寻找最近公共祖先 class Solution { public: // 返回的是最近公共祖先
阅读全文
摘要:https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 思路和106. 从中序与后序遍历序列构造二叉树相同 /** * Definition for a binary tree
阅读全文
摘要:https://leetcode.cn/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 要点是明白中序和后序如何构造二叉树的,并且需要理清当前递归函数的语义,不要一开始就陷入细节,而是思考整棵树与其左右子树的关
阅读全文

浙公网安备 33010602011771号