摘要: ``` /** * 104. Maximum Depth of Binary Tree * 1. Time:O(n) Space:O(h) * 2. Time:O(n) Space:O(h) * 3. Time:O(n) Space:O(h) */ // 1. Time:O(n) Space:O(h) class Solution { public int maxDepth(TreeNode ro 阅读全文
posted @ 2020-05-08 11:08 AAAmsl 阅读(64) 评论(0) 推荐(0) 编辑
摘要: ```/** * 230. Kth Smallest Element in a BST * 1. Time:O(n) Space:O(n) * 2. Time:O(h+k) Space:O(h+k) * 3. Time:O(h+k) Space:O(h+k) */// 1. Time:O(n) Space:O(n)class Solution { public int kthSmal... 阅读全文
posted @ 2020-05-08 11:07 AAAmsl 阅读(49) 评论(0) 推荐(0) 编辑
摘要: ```/** * 235. Lowest Common Ancestor of a Binary Search Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(1) */// 1. Time:O(n) Space:O(n)class Solution { public TreeNode lowestCommonAncestor... 阅读全文
posted @ 2020-05-07 12:00 AAAmsl 阅读(80) 评论(0) 推荐(0) 编辑
摘要: ``` /** * 109. Convert Sorted List to Binary Search Tree * 1. Time:O(nlogn) Space:O(logn) * 2. Time:O(n) Space:O(logn) */ // 1. Time:O(nlogn) Space:O(logn) class Solution { public TreeNode sortedListT 阅读全文
posted @ 2020-05-07 11:58 AAAmsl 阅读(54) 评论(0) 推荐(0) 编辑
摘要: ``` /** * 108. Convert Sorted Array to Binary Search Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { private int[] nums; public TreeNode sortedA 阅读全文
posted @ 2020-05-07 11:57 AAAmsl 阅读(86) 评论(0) 推荐(0) 编辑
摘要: ``` /** * 98. Validate Binary Search Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public boolean isValidBST(TreeNode root) { return helper(ro 阅读全文
posted @ 2020-05-07 11:56 AAAmsl 阅读(64) 评论(0) 推荐(0) 编辑
摘要: ``` /** * 114. Flatten Binary Tree to Linked List * 1. Time:O(n) Space:O(logn) * 2. Time:O(n) Space:O(1) * 3. Time:O(n) Space:O(logn) */ // 1. Time:O(n) Space:O(logn) class Solution { public void flat 阅读全文
posted @ 2020-04-29 11:14 AAAmsl 阅读(95) 评论(0) 推荐(0) 编辑
摘要: ``` /** * 110. Balanced Binary Tree * 1. Time:O(n) Space:O(logn) */ // 1. Time:O(n) Space:O(logn) class Solution { public boolean isBalanced(TreeNode root) { return helper(root)>=0; } public int helpe 阅读全文
posted @ 2020-04-29 11:13 AAAmsl 阅读(72) 评论(0) 推荐(0) 编辑
摘要: ``` /** * 101. Symmetric Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public boolean isSymmetric(TreeNode root) { return isMirror(root,root); 阅读全文
posted @ 2020-04-29 11:12 AAAmsl 阅读(93) 评论(0) 推荐(0) 编辑
摘要: ``` /** * 100. Same Tree * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) */ // 1. Time:O(n) Space:O(n) class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p==null && q==null) r 阅读全文
posted @ 2020-04-29 11:11 AAAmsl 阅读(60) 评论(0) 推荐(0) 编辑