题目:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. ...
分类:
其他好文 时间:
2015-08-28 12:40:19
阅读次数:
194
from leetcode?https://leetcode.com/problems/verify-preorder-sequence-in-binary-search-tree/ 比如序列 2, 1, 3 是如下图的BST的preorder 序列: 但是2, 3, 1就不会是一个preorder序列; 先复习一下BST,给...
分类:
其他好文 时间:
2015-08-27 23:19:14
阅读次数:
681
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Solution 1: recursionruntime: 28ms./** * ...
分类:
其他好文 时间:
2015-08-26 01:36:22
阅读次数:
119
线段树(interval tree),也叫区间树。也是一种二叉搜索树,同一般的BST不同之处在于:线段树的每一个结点包含的是一个区间而不是一个数。具体的描述如下:从图上可以看出,线段树的每一个结点都是一个线段(区间),子节点是对父结点的进一步分划,每个子节点的长度都是父节点的二分,每个叶子结点就.....
分类:
其他好文 时间:
2015-08-21 15:23:51
阅读次数:
193
leetcode - Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in...
分类:
其他好文 时间:
2015-08-20 23:58:08
阅读次数:
393
二叉搜索树的查找——递归算法:boolFind(BTreeNode*BST,ElemType&item) {if(BST==NULL) returnfalse;//查找失败else{ if(item==BST->data){ item=BST->data;//查找成功 return__...
分类:
编程语言 时间:
2015-08-20 20:45:43
阅读次数:
281
题目:
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 ...
分类:
编程语言 时间:
2015-08-20 15:22:03
阅读次数:
180
源代码如下:
#include
#include
//#define Key int
#define hl h->l
#define hr h->r
#define hlr h->l->r
#define hll h->l->l
#define hrr h->r->r
#define hrl h->r->l
typedef int Key;
struct Item{
Key key;
c...
分类:
其他好文 时间:
2015-08-20 13:07:34
阅读次数:
166
先看看实现了哪些功能吧?
(1)构造二叉树
(2)遍历二叉树结点
(3)搜索二叉树结点
(4)删除二叉树结点
(5)判断结点是否存在二叉树
看看源码:
package hk.inso.service;
/**
* Created by IntelliJ IDEA.
* Date: 8/17/15 11:45 PM
* Author: Richar...
分类:
其他好文 时间:
2015-08-20 01:28:40
阅读次数:
182
树状数组第一步,了解如何获取一个整数的最后一位是1的数...
分类:
编程语言 时间:
2015-08-19 20:48:40
阅读次数:
121