当前位置:网站首页>LeetCode 715. Range module
LeetCode 715. Range module
2022-07-07 08:51:00 【Sasakihaise_】

【 Ordered interval 】 Interval splitting and merging , We need to pay attention to add If you encounter [1, 10), [10, 11] This kind should merge them , Because it is possible to query [1, 11] Such a range , So here we use floorKey Come looking for .
class RangeModule {
// Interval splitting and merging 7:21
TreeMap<Integer, Integer> map = new TreeMap();
public RangeModule() {
}
public void show() {
for (var k: map.keySet()) {
System.out.print("[" + k + "," + map.get(k) + "]");
}
System.out.println("====");
}
public void addRange(int left, int right) {
Integer key = map.floorKey(right);
while (key != null) {
int value = map.get(key);
if (value < left) {
break;
}
map.remove(key);
left = Math.min(key, left);
right = Math.max(value, right);
key = map.floorKey(right);
}
map.put(left, right);
// show();
}
public boolean queryRange(int left, int right) {
Integer key = map.floorKey(left);
if (key == null) {
return false;
}
if (map.get(key) >= right) {
return true;
}
return false;
}
public void removeRange(int left, int right) {
Integer key = map.lowerKey(right);
while (key != null) {
int value = map.get(key);
if (value <= left) {
break;
}
map.remove(key);
// key left value right
// key left right value
// left key value right
// left key right value
if (value > right) {
map.put(right, value);
}
if (key < left) {
map.put(key, left);
}
key = map.lowerKey(right);
}
// show();
}
}
/**
* Your RangeModule object will be instantiated and called as such:
* RangeModule obj = new RangeModule();
* obj.addRange(left,right);
* boolean param_2 = obj.queryRange(left,right);
* obj.removeRange(left,right);
*/
边栏推荐
- 求有符号数的原码、反码和补码【C语言】
- What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
- 【MySQL】数据库进阶之触发器内容详解
- leetcode134. gas station
- Count sort (diagram)
- Mountaineering team (DFS)
- Opencv converts 16 bit image data to 8 bits and 8 to 16
- Download and install orcale database11.2.0.4
- Test pits - what test points should be paid attention to when adding fields to existing interfaces (or database tables)?
- 更改当前文件夹及文件夹下文件日期shell脚本
猜你喜欢

What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
![[Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources](/img/e3/3703bdace2d0ca47c1a585562dc15e.jpg)
[Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
![[Nanjing University] - [software analysis] course learning notes (I) -introduction](/img/57/bf652b36389d2bf95388d2eb4772a1.png)
[Nanjing University] - [software analysis] course learning notes (I) -introduction

Greenplum 6.x build_ install

23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP

IP地址的类别

Exercise arrangement 2.10, 11

数据分析方法论与前人经验总结2【笔记干货】

Greenplum6.x常用语句

Greenplum 6.x common statements
随机推荐
let const
更改当前文件夹及文件夹下文件日期shell脚本
Routing information protocol rip
Composer change domestic image
A single game with goods increased by 100000, and the rural anchor sold men's clothes on top of the list?
[MySQL] detailed explanation of trigger content of database advanced
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
Greenplum 6.x build_ install
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - package based on thinkphp5 - detailed guidance of the author - July 6, 2022 - Novice
What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
Virtual address space
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
对API接口或H5接口做签名认证
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
Greenplum 6.x reinitialization
mysql分区讲解及操作语句
Interpolation lookup (two methods)
Appeler l'interface du moteur de création du service multimédia de jeu Huawei renvoie le Code d'erreur 1002, le message d'erreur: les paramètres sont l'erreur
opencv 将16位图像数据转为8位、8转16
阿里p8手把手教你,自动化测试应该如何实现多线程?赶紧码住