Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* ...
分类:
其他好文 时间:
2015-01-14 15:35:32
阅读次数:
178
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *nex...
分类:
其他好文 时间:
2015-01-14 15:33:27
阅读次数:
169
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 diffe...
分类:
其他好文 时间:
2015-01-14 15:33:12
阅读次数:
141
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...
分类:
其他好文 时间:
2015-01-14 09:53:16
阅读次数:
154
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 nodes with keys less than the node's key.Th...
分类:
其他好文 时间:
2015-01-14 09:52:48
阅读次数:
161
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.
For example,
Given n = 3, your program should return all 5 unique BST's shown below.
1 3 ...
分类:
其他好文 时间:
2015-01-14 09:52:27
阅读次数:
150
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?
For example,
Given n = 3, there are a total of 5 unique BST's.
1 3 3 2 1
\ ...
分类:
其他好文 时间:
2015-01-13 19:50:02
阅读次数:
147
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
Calling next() will
return the next smallest number in the BST.
Note: next() a...
分类:
编程语言 时间:
2015-01-13 14:25:39
阅读次数:
240
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-01-13 06:42:51
阅读次数:
201
二叉搜索树,也叫二叉排序树、二叉查找树或BST(Binary Search Tree)。二叉搜索树或是一棵空疏,或者是一棵具有下列特性的非空二叉树:1. 若左子树非空,则左子树上的所有节点的关键字值均小于根节点的关键字的值。2. 若右子树非空,则右子树上的所有节点的关键字值均大于根节点的关键字的值。...
分类:
其他好文 时间:
2015-01-12 22:29:06
阅读次数:
206