摘要:
深度优先搜索 class Solution { int res = Integer.MAX_VALUE; TreeNode prev; public int getMinimumDifference(TreeNode root) { if (root == null){ return 0; } /* 阅读全文
posted @ 2022-02-22 23:41
振袖秋枫问红叶
阅读(46)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { int res = Integer.MAX_VALUE; TreeNode prev; public int minDiffInBST(TreeNode root) { if (root == null){ return 0; } /** * 中序遍历 阅读全文
posted @ 2022-02-22 23:41
振袖秋枫问红叶
阅读(33)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public TreeNode searchBST(TreeNode root, int val) { if (root == null){ return root; } if (root.val == val){ return root; } els 阅读全文
posted @ 2022-02-22 22:11
振袖秋枫问红叶
阅读(24)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public TreeNode mergeTrees(TreeNode root1, TreeNode root2) { /** * 如果某棵树为空,则返回另一棵树 */ if (root1 == null){ return root2; } if ( 阅读全文
posted @ 2022-02-22 21:51
振袖秋枫问红叶
阅读(28)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public TreeNode constructMaximumBinaryTree(int[] nums) { return buildSonTree(nums, 0, nums.length); } /** * 左闭右开区间 * 先找到数组的最大值 阅读全文
posted @ 2022-02-22 21:27
振袖秋枫问红叶
阅读(28)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { return buildSonTree(preorder, 0, preorder.length, inorder, 0, inord 阅读全文
posted @ 2022-02-22 21:14
振袖秋枫问红叶
阅读(39)
评论(0)
推荐(0)
摘要:
深度优先搜索 class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { return buildSonTree(inorder, 0, inorder.length, postorder, 0, post 阅读全文
posted @ 2022-02-22 20:50
振袖秋枫问红叶
阅读(43)
评论(0)
推荐(0)
摘要:
广度优先搜索 class Solution { public int findBottomLeftValue(TreeNode root) { Queue<TreeNode> queue = new LinkedList<>(); int res = 0; queue.add(root); whil 阅读全文
posted @ 2022-02-22 16:06
振袖秋枫问红叶
阅读(22)
评论(0)
推荐(0)