摘要: 今天结束了二叉树的学习, 开始新的一章了 77.组合 class Solution { List<List<Integer>> res = new ArrayList<List<Integer>>(); List<Integer> list = new ArrayList<Integer>(); p 阅读全文
posted @ 2022-11-05 01:37 小猫Soda 阅读(22) 评论(0) 推荐(0)
摘要: 今天终于是 二叉树的最后一章了,三道题,加油! 669. 修剪二叉搜索树 class Solution { public TreeNode trimBST(TreeNode root, int low, int high) { if(root == null){ return root; } roo 阅读全文
posted @ 2022-11-03 14:44 小猫Soda 阅读(12) 评论(0) 推荐(0)
摘要: 今天是第22天,依旧还是二叉树 235. 二叉树的最近公共祖先 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root == null){ retur 阅读全文
posted @ 2022-11-02 13:28 小猫Soda 阅读(19) 评论(0) 推荐(0)
摘要: 今天是第二十一天,还是二叉树,做了得有一周的二叉树了 530.二叉搜索树的最小绝对差 class Solution { int res = Integer.MAX_VALUE; TreeNode pre = null; public int getMinimumDifference(TreeNode 阅读全文
posted @ 2022-11-01 13:47 小猫Soda 阅读(23) 评论(0) 推荐(0)
摘要: 今天还是二叉树 654. 最大二叉树 class Solution { public TreeNode constructMaximumBinaryTree(int[] nums) { int n = nums.length; return maxTree(nums, 0, n - 1); } pu 阅读全文
posted @ 2022-10-31 15:24 小猫Soda 阅读(22) 评论(0) 推荐(0)
摘要: 今天是本周二叉树的最后一章了,内容都是偏难的 513.找树左下角的值 class Solution { public int findBottomLeftValue(TreeNode root) { Queue<TreeNode> q = new LinkedList<>(); q.offer(ro 阅读全文
posted @ 2022-10-30 11:50 小猫Soda 阅读(23) 评论(0) 推荐(0)
摘要: 今天继续二叉树的学习 110. 平衡二叉树 class Solution { public boolean isBalanced(TreeNode root) { return dfs(root)>=0; } public int dfs(TreeNode root){ if(root == nul 阅读全文
posted @ 2022-10-29 14:33 小猫Soda 阅读(19) 评论(0) 推荐(0)
摘要: 今天是第十六天,继续二叉树方面的递归练习 104. 二叉树的最大深度 class Solution { public int maxDepth(TreeNode root) { if(root == null){ return 0; } else{ return Math.max(maxDepth( 阅读全文
posted @ 2022-10-28 14:11 小猫Soda 阅读(20) 评论(0) 推荐(0)
摘要: 今天是训练营的第十五天,继续二叉树方面的学习 迭代法遍历: 前序: class Solution { public List<Integer> preorderTraversal(TreeNode root) { Stack<TreeNode> s = new Stack<>(); List<Int 阅读全文
posted @ 2022-10-27 10:12 小猫Soda 阅读(20) 评论(0) 推荐(0)
摘要: 今天是第十四天,除了二叉树的基本概念外,还有递归法的应用 144. 二叉树的前序遍历 class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> res = new ArrayList< 阅读全文
posted @ 2022-10-26 02:01 小猫Soda 阅读(20) 评论(0) 推荐(0)