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'...
分类:
其他好文 时间:
2014-06-28 11:57:50
阅读次数:
232
题目:Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A ...
分类:
其他好文 时间:
2014-06-28 10:26:38
阅读次数:
253
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.TreeNode *createSearchTree(ListNode *&hea...
分类:
其他好文 时间:
2014-06-26 00:12:57
阅读次数:
289
题目:输入一个整数数组,判断该数组是不是某个二叉搜索树的后序遍历序列假设输入的数组的数字均不相同解题分析:对于二叉搜索树,中序序列一定是升序的,我们将后序遍历序列排序,结果即为 中序遍历序列如果该后序遍历序列是正确的,那么 由 中序遍历序列和后序遍历序列 一定可以构建一棵二叉树如果不能成功构建一棵二...
分类:
其他好文 时间:
2014-06-24 14:10:18
阅读次数:
166
题目:输入一棵BST,将该BST转换成一个排序的双向链表要求不能创建新的结点,只能调整树中结点指针的指向在BST中,左子节点的值 小于父节点的之, 父节点的值小于 右子节点的值因此我们在转换成有序的双向链表时,原先指向左子节点的指针调整为链表中指向前一个结点的指针原先指向右子节点的指针调整为链表中指...
分类:
其他好文 时间:
2014-06-24 13:38:31
阅读次数:
243
题目:Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.个人思路:1、选...
分类:
其他好文 时间:
2014-06-21 06:37:00
阅读次数:
183
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.说明:平衡二叉搜索树,即任何结点的左子树和右子树高度最多相差1的二叉搜索树。二叉搜索树:二叉查找树(Bin...
分类:
其他好文 时间:
2014-06-21 00:47:08
阅读次数:
221
不是BST,那么搜索两节点的LCA就复杂点了,因为节点是无序的。
下面是两种方法,都写进一个类里面了。
当然需要重复搜索的时候,可以使用线段树及多种方法加速搜索。
#include
#include
using namespace std;
class LCANormalTree
{
struct Node
{
int key;
Node *left, *right;...
分类:
其他好文 时间:
2014-06-16 20:20:04
阅读次数:
234
Given an array where elements are sorted in
ascending order, convert it to a height balanced BST.递归,二分法。 1 /** 2 *
Definition for binary tree 3 * st.....
分类:
其他好文 时间:
2014-06-16 00:33:31
阅读次数:
252
1、
??
Unique Binary Search Trees II
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 uni...
分类:
其他好文 时间:
2014-06-15 09:09:00
阅读次数:
256