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-08-30 01:10:48
阅读次数:
333
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 pretty straight forward. Could you devis...
分类:
其他好文 时间:
2014-08-29 21:28:08
阅读次数:
313
LeetCode: Validata Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The l...
分类:
其他好文 时间:
2014-08-28 23:59:16
阅读次数:
421
LeetCode: Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure....
分类:
其他好文 时间:
2014-08-28 23:58:36
阅读次数:
385
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...
分类:
其他好文 时间:
2014-08-28 20:57:46
阅读次数:
201
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 ...
分类:
其他好文 时间:
2014-08-28 19:33:55
阅读次数:
266
二叉搜索树(Binary Search Tree,BST)的一点总结。...
分类:
其他好文 时间:
2014-08-28 14:52:59
阅读次数:
215
给定有序链表(元素由小到大), 试问如何将其转换为一个平衡BST?平衡BST: 任意节点的左右子树的深度差值不大于1.主要思想是用递归. Trick是使用快慢指针来获取中间节点. 获得中间节点后, 将其设为此次递归的root, 随后删除此节点, 并将前一节点的next置NULL. 随后, 对中间节点...
分类:
其他好文 时间:
2014-08-28 11:15:19
阅读次数:
162
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.方法:将有序数组转为平...
分类:
其他好文 时间:
2014-08-27 23:17:18
阅读次数:
278
UVA 10821 - Constructing BST
题目链接
题意:有1 - n的数字,要构造一棵高度不超过h的BST,并且要字典序最小的,输出序列
思路:贪心构造,既然字典序最小,那么每个子树的根都要尽量小,那么也就是右子树尽量填满,按照这个策略去dfs构造即可
代码:
#include
#include
#include
using namespace...
分类:
其他好文 时间:
2014-08-25 14:59:04
阅读次数:
196