上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 22 下一页
摘要: 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... 阅读全文
posted @ 2018-09-21 07:49 jasoncool1 阅读(77) 评论(0) 推荐(0) 编辑
摘要: https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/discuss/35476/Share-my-JAVA-solution-1ms-very-short-and-concise. 阅读全文
posted @ 2018-09-20 10:29 jasoncool1 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-09-20 07:32 jasoncool1 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-09-20 06:56 jasoncool1 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-09-20 06:44 jasoncool1 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2018-09-20 05:54 jasoncool1 阅读(139) 评论(0) 推荐(0) 编辑
摘要: https://leetcode.com/problems/symmetric-tree/discuss/166375/Java-Accepted-very-simple-solution 阅读全文
posted @ 2018-09-20 04:28 jasoncool1 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 分成两边, left right排列组合加到root, lo==hi就返回当前值 阅读全文
posted @ 2018-09-18 10:57 jasoncool1 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 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) 阅读全文
posted @ 2018-09-17 12:47 jasoncool1 阅读(97) 评论(0) 推荐(0) 编辑
摘要: 1 //Recursive 2 class Solution { 3 List res = new ArrayList(); 4 public List inorderTraversal(TreeNode root) { 5 if (root != null) { 6 inorderTraversal(root.left)... 阅读全文
posted @ 2018-09-17 05:49 jasoncool1 阅读(100) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 22 下一页