201. Segment Tree Build
最后更新
二刷
08-Jan-2017
一刷忘了什么时候做的,只是觉得这几个题挺好的,一步一步手动构建线段树,最终理解了这个数据结构,并且后面有利用的地方。
其实重要的3个东西题目已经提供了:
- left < right return null
- left == right return root
- (left, mid), (mid+1, right)
public class Solution {
public SegmentTreeNode build(int start, int end) {
if (start > end) return null;
SegmentTreeNode tempRoot = new SegmentTreeNode(start, end);
if (start == end) return tempRoot;
int mid = start + (end - start) / 2;
tempRoot.left = build(start, mid);
tempRoot.right = build(mid + 1, end);
return tempRoot;
}
}
201. Segment Tree Build的更多相关文章
- [LintCode] Segment Tree Build II 建立线段树之二
The structure of Segment Tree is a binary tree which each node has two attributes startand end denot ...
- Segment Tree Build I & II
Segment Tree Build I The structure of Segment Tree is a binary tree which each node has two attribut ...
- [LintCode] Segment Tree Build 建立线段树
The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...
- Lintcode: Segment Tree Build
The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...
- 439. Segment Tree Build II
最后更新 08-Jan-2017 开始介绍线段树的主要作用了,可以快速在区间查找极值,我猜是这样的..... 一个NODE的最大值取决于它左边和右边最大值里大 按个,所以,所以什么?对了,我们该用po ...
- Lintcode: Segment Tree Modify
For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...
- Lintcode247 Segment Tree Query II solution 题解
[题目描述] For an array, we can build a Segment Tree for it, each node stores an extra attribute count t ...
- Segment Tree Query I & II
Segment Tree Query I For an integer array (index from 0 to n-1, where n is the size of this array), ...
- Lintcode: Segment Tree Query II
For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ...
随机推荐
- 关于ie6对齐
先来没有任何对齐时的样子: 1.一种是在父级没有高度的情况下居中. 给每个独立的元素都加上vertical-align:middle; 针对文字可以不加,加与不加都可以居中对齐.但是无法做到绝对的居中 ...
- [转帖]Asp.NET 弹出页面
原文链接:http://www.cnblogs.com/adi-liu/archive/2008/07/18/1246091.html ASP.NET 弹出对话框和页面之间传递值的经验总结 今天碰到一 ...
- [Sciter系列] MFC下的Sciter–2.Sciter中的事件,tiscript,语法
[Sciter系列] MFC下的Sciter–2.Sciter中的事件,tiscript,CSS部分自觉学习,重点说明Tiscript部分的常见语法和事件用法. 本系列文章的目的就是一步步构建出一个功 ...
- java中的final、finally和finalize
最近在读Thinking In Java,秉着有些地方还能知道自己不会的精神,都去好好查阅了一些资料,在内存分配这一章,看到finalize()这个方法,刚开始很不理解,查阅了一些资料,顺带看了一下f ...
- j2ee的13个标准
1:JDBC(Java Database Connectivity)JDBC API为访问不同数据库提供了统一的路径,向ODBC一样,JDBC开发者屏蔽了一些细节问题,另外,JDBC对数据库的访问也具 ...
- Oracle数据库启动时:ORA-00119: invalid specification for system parameter LOCAL_LISTENER; ORA-00132错误解决
问题描述: 1. em打开中提示 https://localhost:1158/em/console/database/instance/repDown?target=orclweng&typ ...
- Corn Fields(POJ 3254状压dp)
题意: n*m网格1能放0不能放 放的格子不能相邻 求一共多少种可放的方案. 分析: dp[i][j]第i行可行状态j的的最大方案数,枚举当前行和前一行的所有状态转移就行了(不放牛也算一种情况) #i ...
- word编号库中找不到带圈编号“①②③......"了怎么办?
进入“Word选项/语言”对话框: 找到“朝鲜语”并将它添加到编辑语言的列表框中,无需设置为启用状态或默认编辑语言: 退出并重新启动Word: 再次打开“定义新编号格式”对话框则可以在“编号样式”下拉 ...
- 为cocos2d-x项目增加Lua支持
开始为游戏增加Lua脚本支持,今天主要配置了一下开发环境:cocos2d-x 2.2.1,xcode5. 1. 创建cocos2d-x-lua项目 类似于创建C++项目,用以下命令即可: python ...
- 教你利用iframe在网页中显示天气
来源:http://www.ido321.com/921.html css: 1: *{margin:0;padding:0;list-style-type:none;} 2: a,img{borde ...