可以发现 当第i-1个比第i个高的时候 比第i-1个高的所有也一定比第i个高
于是可以用到动态规划的思想
令left[i]表示包括i在内比i高的连续序列中最左边一个的编号 right[i]为最右边一个的编号
那么有 当h[left[i]-1]>=h[i]]时 left[i]=left[left[i]-1] 从前往后可以递推出left[i]
同理 当h[right[i]+1]>=h[i]]时 right[i]=right[right[i]+1] 从后往前可递推...
分类:
其他好文 时间:
2014-08-05 09:39:49
阅读次数:
276
最近在项目中用到了,特地搬运过来。Kd-树 其实是K-dimension tree的缩写,是对数据点在k维空间中划分的一种数据结构。其实,Kd-树是一种平衡二叉树。举一示例:假设有六个二维数据点 = {(2,3),(5,4),(9,6),(4,7),(8,1),(7,2)},数据点位于二维空间中。为...
分类:
其他好文 时间:
2014-08-05 09:30:38
阅读次数:
321
题目:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree....
分类:
编程语言 时间:
2014-08-05 05:18:28
阅读次数:
242
题目:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).F....
分类:
编程语言 时间:
2014-08-05 05:18:08
阅读次数:
340
题目:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level ....
分类:
编程语言 时间:
2014-08-05 05:17:38
阅读次数:
311
题目: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....
分类:
编程语言 时间:
2014-08-05 05:17:28
阅读次数:
265
都是自己在实践过程中遇到的,首先是自己安装apache-maven进行简单的认识学习的时候想看看my-app项目的tree结果发现bash:treecommandnotfound解决这个问题,在查阅资料后发现,前提是我是centos6.5的最小化安装在家目录下打开文件.bash_profile后发现PATH=$PATH:$HOME/bin将其..
分类:
其他好文 时间:
2014-08-05 03:15:28
阅读次数:
245
An example of in-order traversal application. My intuition is that, we have to serialize it into an array and check, but in-order traversal does exact...
分类:
其他好文 时间:
2014-08-05 03:03:48
阅读次数:
241
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
You may only use constant ...
分类:
其他好文 时间:
2014-08-05 00:51:38
阅读次数:
249
Apple Tree
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 7120
Accepted: 2370
Description
Wshxzt is a lovely girl. She likes apple very much. One day HX tak...
分类:
移动开发 时间:
2014-08-05 00:50:38
阅读次数:
310