上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 21 下一页
摘要: https://leetcode.cn/problems/candy/description/ 贪心,策略是确定一侧的正确性,再确定另一侧的正确性,最后综合作为正确答案,其中先确定一侧的正确性是局部最优,确定两侧的正确性的局部最优,且找不到反例就可以推出全局最优答案 class Solution { 阅读全文
posted @ 2024-08-27 21:47 风乐 阅读(19) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/gas-station/ 贪心,原理是: 如果x能到达y,不能到达y+1,那么x-y之间的点也不可能到达y+1:z为xy之间一点,从x开始到z(在z加油前),剩余油量一定大等于0,但是从z开始的话,起始油量一定等于0 >> 起始油量大等于0都 阅读全文
posted @ 2024-08-24 00:03 风乐 阅读(17) 评论(0) 推荐(0)
摘要: https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3?tpId=37&tqId=21331&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta% 阅读全文
posted @ 2024-06-15 01:44 风乐 阅读(31) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/combination-sum-ii/description/ class Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = 阅读全文
posted @ 2024-05-16 12:41 风乐 阅读(15) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/combination-sum/description/ 两种搜索思路 一种是选或不选,搜索树是一颗二叉树另一种是选哪个数,是一个n叉树 二叉 class Solution { List<List<Integer>> res = new Ar 阅读全文
posted @ 2024-05-15 22:40 风乐 阅读(7) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/description/ 要点是分割左右区间,并且分割时需要注意left和right相加可能会超过int,但是本题不需要 class Solution { 阅读全文
posted @ 2024-05-15 16:51 风乐 阅读(12) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/trim-a-binary-search-tree/description/ 要点是区分在区间左边还是右边,在区间左边那么右子树也还有必要去查找删除,右边同理,返回的是删除后新树的根节点 要注意函数要实现单层逻辑和完成闭环语义 class S 阅读全文
posted @ 2024-05-11 14:03 风乐 阅读(14) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/delete-node-in-a-bst/ 要点是确定函数语义,单层递归逻辑,确定好有返回值的这种写法,分析出5种情况,递归的时候接收好递归的返回的新树的根节点即可 class Solution { // 函数语义(单层递归逻辑):查找要删除 阅读全文
posted @ 2024-05-11 12:31 风乐 阅读(29) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/insert-into-a-binary-search-tree/ 推荐使用没有返回值的方法,因为比较好想233 递归法: class Solution { public: TreeNode* pre=nullptr; TreeNode* i 阅读全文
posted @ 2024-05-10 11:14 风乐 阅读(9) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-search-tree/ 明确函数的返回值和参数,返回最近公共祖先,没有就返回null 单层递归逻辑是:若按搜索树条件,递归左子树未查询到,递归右子树也未查询到,那么意味着 阅读全文
posted @ 2024-05-08 23:43 风乐 阅读(19) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 21 下一页