二叉平衡树好火啊,几乎每个公司的笔试题里都有它,考了好多次我都不会,挂笔试很有可能就是因为它,还有一个它的同伙叫二叉搜索树,貌似人气比它还要高一些。二叉平衡树是什么样的树呢,是每个节点的左右子树高度相差绝对值都不超过1。好,你说你终于回了,这不很简单吗,求一下根节点的左右字数高度,如果满足,他就是,否则就不是嘛。不是啊亲,要求是所有节点都满足这个条件,判断的时候必须每个节点都验证的!
扯了这么长...
                            
                            
                                分类:
其他好文   时间:
2014-05-08 11:05:26   
                                阅读次数:
286
                             
                    
                        
                            
                            
                                Given an array where elements are sorted in 
ascending order, convert it to a height balanced BST./** * Definition for binary 
tree * public class TreeN...
                            
                            
                                分类:
其他好文   时间:
2014-05-08 00:51:46   
                                阅读次数:
430
                             
                    
                        
                            
                            
                                很锻炼DP/recursive思路的一道题,个人感觉DP/recursive算是比较难写的题目了。这道题解法的巧妙之处在于巧用-1,并且使用临时存储,节省了很多开支。这道题同时也在Career 
Cup上面出现过这道题我两次调试通过,第一次错是因为input{}, output false, expe...
                            
                            
                                分类:
其他好文   时间:
2014-05-05 22:45:10   
                                阅读次数:
352
                             
                    
                        
                            
                            
                                Link:http://oj.leetcode.com/problems/balanced-binary-tree/Given a binary tree, 
determine if it is height-balanced.For this problem, a height-balanced ...
                            
                            
                                分类:
其他好文   时间:
2014-05-05 22:29:55   
                                阅读次数:
382
                             
                    
                        
                            
                            
                                问题:给一个二叉树,写一个算法判断这个树是不是balanced。Solution 
#1.第一次遇到这个问题时我的解法,如下:public class Solution { public boolean isBalanced(TreeNode 
root) { if(root == ...
                            
                            
                                分类:
其他好文   时间:
2014-05-05 12:50:49   
                                阅读次数:
263
                             
                    
                        
                            
                            
                                判断树是否是平衡的,这道题中的平衡的概念是指任意节点的两个子树的高度相差不超过1,我用递归的方法把所有的节点的高度都计算了下,并且在计算的过程记录每个节点左右两颗子树的高度差,最后通过遍历这个高度差就可以知道是否是平衡的。下面是AC代码: 
1 /** 2 * Given a binary...
                            
                            
                                分类:
其他好文   时间:
2014-05-05 09:54:44   
                                阅读次数:
378
                             
                    
                        
                            
                            
                                Given a binary tree, determine if it is 
height-balanced.For this problem, a height-balanced binary tree is defined as a 
binary tree in which the depth...
                            
                            
                                分类:
其他好文   时间:
2014-05-02 07:05:08   
                                阅读次数:
311
                             
                    
                        
                            
                            
                                Given a binary tree, determine if it is 
height-balanced.For this problem, a height-balanced binary tree is defined as a 
binary tree in which the depth...
                            
                            
                                分类:
其他好文   时间:
2014-05-01 14:38:39   
                                阅读次数:
454
                             
                    
                        
                            
                            
                                Balanced Lineup
Time Limit: 5000MS
 
Memory Limit: 65536K
Total Submissions: 32070
 
Accepted: 15090
Case Time Limit: 2000MS
Description
For the daily milking, Far...
                            
                            
                                分类:
其他好文   时间:
2014-04-27 22:44:53   
                                阅读次数:
302