摘要:
1 class Solution { 2 public boolean isBalanced(TreeNode root) { 3 if(root == null) return true; 4 return(isBalanced(root.left) && isBalanced(root.right) && Math.abs(dfs(root.l... 阅读全文
摘要:
https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/discuss/35476/Share-my-JAVA-solution-1ms-very-short-and-concise. 阅读全文
摘要:
1 class Solution { 2 public TreeNode sortedArrayToBST(int[] nums) { 3 int size = nums.length; 4 return helper(nums, 0, size - 1); 5 6 } 7 8 public Tr... 阅读全文
摘要:
1 class Solution { 2 public List> levelOrderBottom(TreeNode root) { 3 Queue queue = new LinkedList(); 4 List> res = new ArrayList(); 5 if(root == null) return res; 6... 阅读全文
摘要:
1 class Solution { 2 public TreeNode buildTree(int[] inorder, int[] postorder) { 3 return helper(postorder.length-1, 0, inorder.length - 1, inorder, postorder); 4 5 } 6... 阅读全文
摘要:
1 //New 用一个记录queue.size()就可以 2 class Solution { 3 public List> zigzagLevelOrder(TreeNode root) { 4 List> res = new ArrayList(); 5 if(root == null) return res; 6 Queu... 阅读全文
摘要:
https://leetcode.com/problems/symmetric-tree/discuss/166375/Java-Accepted-very-simple-solution 阅读全文
摘要:
分成两边, left right排列组合加到root, lo==hi就返回当前值 阅读全文
摘要:
https://leetcode.com/problems/unique-binary-search-trees/discuss/31666/DP-Solution-in-6-lines-with-explanation.-F(i-n)-G(i-1)-*-G(n-i) 阅读全文
摘要:
1 //Recursive 2 class Solution { 3 List res = new ArrayList(); 4 public List inorderTraversal(TreeNode root) { 5 if (root != null) { 6 inorderTraversal(root.left)... 阅读全文