题目
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
方法
数组是有序的,要求创建的二叉树尽量平衡,很容易想到对数组进行二分操作,左边的数组元素是左子树,右边的数组元素是右子树。进行递归操作就可以了。
	TreeNode...
                            
                            
                                分类:
其他好文   时间:
2014-06-20 11:06:46   
                                阅读次数:
257
                             
                    
                        
                            
                            
                                【题目】
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
【题意】
给定一个已排序的数组(不存在重复元素),将它转换成一棵平衡二叉搜索树。
【思路】
由于平衡二叉树要求左右子树的高度差绝对值相遇等于1,也就是说左右子树尽可能包含相同数目节点。
则使用二分法来解本题即可。...
                            
                            
                                分类:
其他好文   时间:
2014-06-20 11:03:31   
                                阅读次数:
246
                             
                    
                        
                            
                            
                                【题目】
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 of the two subtrees of every node never differ by more than 1.
【题意】
判断二叉树是否是平衡二叉树
【思路】
平衡二...
                            
                            
                                分类:
其他好文   时间:
2014-06-20 11:02:54   
                                阅读次数:
173
                             
                    
                        
                            
                            
                                题目
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
方法
和有序数组的思想基本一样,将链表进行二分。
	TreeNode getBST(ListNode head, int len) {
		i...
                            
                            
                                分类:
其他好文   时间:
2014-06-20 09:46:33   
                                阅读次数:
267
                             
                    
                        
                            
                            
                                题目
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 of the two subtrees of every node...
                            
                            
                                分类:
其他好文   时间:
2014-06-20 09:02:56   
                                阅读次数:
232
                             
                    
                        
                            
                            
                                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-06-11 21:58:10   
                                阅读次数:
300
                             
                    
                        
                            
                            
                                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-06-10 00:54:41   
                                阅读次数:
313
                             
                    
                        
                            
                            
                                Given a singly linked list where elements are 
sorted in ascending order, convert it to a height balanced BST.public class 
Solution { /** Convert th...
                            
                            
                                分类:
其他好文   时间:
2014-06-10 00:22:44   
                                阅读次数:
259
                             
                    
                        
                            
                            
                                题目链接题意: 给定一棵二叉树, 判断是否为平衡二叉树, 这里的平衡二叉树指的是:每个结点的左右子树的深度之差不超过1。附上代码: 
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * ...
                            
                            
                                分类:
其他好文   时间:
2014-06-08 18:58:35   
                                阅读次数:
194
                             
                    
                        
                            
                            
                                【题目】
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
【题意】
将一个有序链表转换成平衡二叉树
【思路】
思路跟Convert Sorted Array to Binary Search Tree完全一样...
                            
                            
                                分类:
其他好文   时间:
2014-06-07 16:20:05   
                                阅读次数:
287