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-07-31 16:08:26
阅读次数:
283
//私有的:private //公有的:public //受保护的:protected 只能在只有在分类和子类中可以访问 //静态的 static 无需实例化,可直接调用,不能用private定义 //密封的 sealed 不能被重写,不能别继承, //抽象的 abstact
分类:
其他好文 时间:
2014-07-31 09:40:25
阅读次数:
212
题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题解:先复习下什么是二叉搜索树(引自Wikipedia):二叉查找树(Binary Search ....
分类:
编程语言 时间:
2014-07-31 05:21:55
阅读次数:
215
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...
分类:
其他好文 时间:
2014-07-30 17:46:04
阅读次数:
244
php获取文件名$phpself =$_SERVER['PHP_SELF']; //获取当前文件名$str = end(explode("/",$phpself)); //去掉'/'echo $str.""; //输出文件全名echo substr($str,0,strrpos($str, '...
分类:
Web程序 时间:
2014-07-29 17:14:22
阅读次数:
225
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.题意:给定一个有序的链表,将其转换成平衡二叉搜索树思路: 二分法要构建一个平衡二叉...
分类:
其他好文 时间:
2014-07-29 13:40:48
阅读次数:
601
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
\...
分类:
编程语言 时间:
2014-07-24 11:35:42
阅读次数:
245
题意:
给你个序列和一串询问 询问前a[i]个数字第i小的是几
思路:
动态的第k值问题 由于区间只增不减所以是水题
利用平衡树解决这类问题
treap是方便编写的类似平衡树的产品
treap方便实现BST的功能 splay更适合于去维护区间
代码:
#include
#include
#include
#include
#include
using name...
分类:
其他好文 时间:
2014-07-23 22:35:48
阅读次数:
234
如果领悟了树状数组中的lowbit,这道题就是极其简单的,最底层都是奇数,用lowbit(x)寻找x的父亲,然后x的父亲-1就是最大数
至于lowbit是如何计算的嘛,寻找x的父亲,其实就是x+2^x的二进制末尾0的个数。
#include
#include
using namespace std;
typedef long long ll;
ll lowbit(int x){
re...
分类:
其他好文 时间:
2014-07-23 13:12:16
阅读次数:
273
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.题解:开始想到的方法比较偷懒,直接遍历一遍数组,把每个ListNode对应的值放到...
分类:
其他好文 时间:
2014-07-22 22:45:13
阅读次数:
271