247. Segment Tree Query II
最后更新
二刷
09-Jna-2017
利用线段树进行区间查找,重点还是如何判断每一层的覆盖区间,和覆盖去见与当前NODE值域的关系。
public class Solution {
    public int query(SegmentTreeNode root, int start, int end) {
        if (root == null) return 0;
        if (start > root.end || end < root.start) return 0;
        int coveredStart = Math.max(start, root.start);
        int coveredEnd = Math.min(end, root.end);
        if (root.start == coveredStart && root.end == coveredEnd) return root.count;
        return query(root.left, coveredStart, coveredEnd) +
               query(root.right, coveredStart, coveredEnd);
    }
}
247. Segment Tree Query II的更多相关文章
- Lintcode: Segment Tree Query II
		For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ... 
- 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
		For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding ... 
- [LintCode] Segment Tree Build II 建立线段树之二
		The structure of Segment Tree is a binary tree which each node has two attributes startand end denot ... 
- 202. Segment Tree Query
		最后更新 二刷 09-Jan-17 正儿八经线段树的应用了. 查找区间内的值. 对于某一个Node,有这样的可能: 1)需要查找区间和当前NODE没有覆盖部分,那么直接回去就行了. 2)有覆盖的部分, ... 
- 439. Segment Tree Build II
		最后更新 08-Jan-2017 开始介绍线段树的主要作用了,可以快速在区间查找极值,我猜是这样的..... 一个NODE的最大值取决于它左边和右边最大值里大 按个,所以,所以什么?对了,我们该用po ... 
- 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 Modify
		For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ... 
随机推荐
- largest rectangle in histogram leetcode
			Given n non-negative integers representing the histogram's bar height where the width of each bar is ... 
- postman使用--批量执行测试用例和数据驱动
			批量执行 在我们测试接口的时候,有时候希望执行所有的测试用例,前面讲的都是测试单个的接口,postman提供了我们批量执行接口的功能 点击Runner 然后我们点击run 执行完会统计出我们的结果,失 ... 
- vue计算属性computed和methods的区别
			computed和methods的区别 在new Vue的配置参数中的computed和methods都可以处理大量的逻辑代码,但是什么时候用哪个属性,要好好区分一下才能做到正确的运用vue. com ... 
- jQuery判断一个元素是否为另一个元素的子元素(或者其本身)
			<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head& ... 
- 题解 洛谷P3622/BZOJ1151【[APIO2007]动物园】
			这一道题,我也是搞了很久才搞懂的(也就两个多小时). 感谢Rayment大佬的题解! 我们进入正题. 对于一个笼子里的动物,我们可以选择撤走或不撤走,可以用0和1来表示,很容易就想到二进制,想到状压d ... 
- luogu P1821 Silver Cow Party
			题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ... 
- 文件默认权限umask掩码
			umask命令 作用:用于显示.设置文件的缺省权限 格式:umask [-S] -S表示以rwx形式显示新建文件缺省权限 系统的默认掩码是0022 文件创建时的默认权限 = 0666 - umas ... 
- turtle安装问题
			原文来源:https://blog.csdn.net/liudongdong19/article/details/81283942 本人python版本为:Python 3.6.5 在安装turtle ... 
- 20.	ROUTINES
			20. ROUTINES ROUTINES表提供有关存储例程(存储过程和存储函数)的信息. ROUTINES表不包含内置SQL函数或用户定义函数(UDF). 名为mysql.proc Name的列表示 ... 
- 记第一次面试的悲惨经历QAQ
			面试岗位:测试开发 自我介绍 :根据介绍的内容,会问简历上涉及到的东西,主要是项目: 手写代码:给一个数组,求数组中所有数字拼接后能得到的最小数字.例:{3,32,312},输出312323. 关于计 ... 
