上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 36 下一页
摘要: 深度优先搜索 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 振袖秋枫问红叶 阅读(23) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { public TreeNode mergeTrees(TreeNode root1, TreeNode root2) { /** * 如果某棵树为空,则返回另一棵树 */ if (root1 == null){ return root2; } if ( 阅读全文
posted @ 2022-02-22 21:51 振袖秋枫问红叶 阅读(27) 评论(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)
摘要: 深度优先搜索 /** * 时间复杂度 O(n) * 空间复杂度 O(logn) */class Solution { public int maxDepth(Node root) { if (root == null){ return 0; } int max = 0; for (Node c : 阅读全文
posted @ 2022-02-21 17:54 振袖秋枫问红叶 阅读(26) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { public boolean isSubtree(TreeNode root, TreeNode subRoot) { /** * 对于树的每个节点,都判断一下是否和子树是一个树(《100. 相同的树》) */ if (subRoot == null) 阅读全文
posted @ 2022-02-21 17:11 振袖秋枫问红叶 阅读(23) 评论(0) 推荐(0)
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 36 下一页