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 ...
随机推荐
- Linux php安装zip扩展
Linux php安装zip扩展 2018.07.22 22:40 1165浏览 #wget http://pecl.php.net/get/zip-1.12.4.tgz #tar zxfv zi ...
- Spread / Rest 操作符
Spread / Rest 操作符指的是 ...,具体是 Spread 还是 Rest 需要看上下文语境. 当被用于迭代器中时,它是一个 Spread 操作符:(参数为数组) function foo ...
- POJ-2442-Sequence(二叉堆)
POJ-2442 Description Given m sequences, each contains n non-negative integer. Now we may select one ...
- 3 SQL 聚合与排序
3 聚合与排序 3-1 对表进行聚合查询 聚合函数 通过SQL对数据进行 操作或计算时需要使用函数. 计算表中全部数据行数时,可以使用COUNT函数. COUNT : 计算表中的记录数(行数). SU ...
- 201621123079《java程序设计》第六周作业总结
作业06-接口.内部类 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 2. 书面作业 1. c ...
- 测试网站链接是否可用(wget和curl)
一.wget用法案例 系统给的命令参数如下: [root@litong_centos mysql3307]# wget --help GNU Wget 1.14, a non-interactive ...
- redis:安装配置主从
1.安装依赖包 yum install gcc gcc-c++ -y 2.下载安装包,解压 cd /usr/local/src/wget http://download.redis.io/releas ...
- MySQL教程之存储过程与函数
存储程序分为存储过程和函数 可以使用CALL来调用存储过程,只能输出变量返回值.存储过程可以调用其他存储过程 函数可以从语句外调用,也能返回标量值 什么是存储过程? 简单的说,就是一组SQL语句集,功 ...
- python re 正则表达式
元字符和其含义 . 匹配除换行符以外的任意字符 \ 转义字符,使后一个字符改变原来的意思 \w 匹配字母.数字.下划线:[A-Za-z0-9_] \W 匹配特殊字符:[^A-Za-z0-9_] \s ...
- jquery select 常用操作总结
由于在项目各种所需,经常碰到select不种操作的要求,今天特意总结了一下,分享: jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id&q ...