超简洁的代码本来考虑是不是真的要每个点求一个maxDepth,看来是的哟public class Solution { public boolean isBalanced(TreeNode root) { if (root==null) return true; i...
分类:
其他好文 时间:
2015-06-10 06:35:56
阅读次数:
88
就recursive做,简单题public class Solution { public int minDepth(TreeNode root) { if(root==null) return 0; if (root.left==null && root.righ...
分类:
其他好文 时间:
2015-06-10 06:35:28
阅读次数:
138
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le...
分类:
其他好文 时间:
2015-06-10 06:33:56
阅读次数:
99
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题解完全抄自ref的说明,感谢!“题解:先复习下什么是二叉搜索树(引自Wikipedia):二叉查找树(B...
分类:
其他好文 时间:
2015-06-10 06:33:38
阅读次数:
112
简单题IGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given su...
分类:
其他好文 时间:
2015-06-10 06:33:31
阅读次数:
101
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
分类:
其他好文 时间:
2015-06-10 06:32:56
阅读次数:
115
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ...
分类:
其他好文 时间:
2015-06-10 06:32:31
阅读次数:
106
跟之前的解法一模一样Binary Tree Level Order Traversal I,II 不赘述public class Solution { public ArrayList> zigzagLevelOrder(TreeNode root) { ArrayList> r...
分类:
其他好文 时间:
2015-06-10 06:31:24
阅读次数:
94
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n...
分类:
其他好文 时间:
2015-06-10 06:27:16
阅读次数:
102
平衡二叉树(Self-Balancing Binary Search Tree/Height-Balanced Binary Search Tree),是一种二叉排序树,其中每一个节点的左子树和右子树的高度差至多等于1.平衡二叉树的前提是二叉排序树,不是二叉排序树的都不是平衡二叉树。
平衡因子BF(Balance Factor):二叉树上节点的左子树深度减去右子树深度的值。最小不平衡子树:距离插入...
分类:
其他好文 时间:
2015-06-09 23:48:22
阅读次数:
414