当前位置:网站首页>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);
*/
边栏推荐
- NCS Chengdu Xindian interview experience
- idea里使用module项目的一个bug
- Gson转换实体类为json时报declares multiple JSON fields named
- [Yugong series] February 2022 U3D full stack class 008 - build a galaxy scene
- Rapid integration of authentication services - harmonyos platform
- [Yugong series] February 2022 U3D full stack class 006 unity toolbar
- Introduction to data fragmentation
- [hard core science popularization] working principle of dynamic loop monitoring system
- Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
- String operation
猜你喜欢

Greenplum6.x搭建_安装

关于基于kangle和EP面板使用CDN

Interpolation lookup (two methods)

JS的操作

Rapid integration of authentication services - harmonyos platform

Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
![[Yugong series] February 2022 U3D full stack class 006 unity toolbar](/img/2e/3a7d71a0b5a6aff294a0bd2f8515f8.jpg)
[Yugong series] February 2022 U3D full stack class 006 unity toolbar

Download and install orcale database11.2.0.4
![[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

Input and output of floating point data (C language)
随机推荐
IP地址的类别
Greenplum 6.x common statements
JS的操作
xray的简单使用
Three usage scenarios of annotation @configurationproperties
Shell script for changing the current folder and the file date under the folder
对API接口或H5接口做签名认证
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月6日-新手快速上手-可无缝升级tp6版本
Greenplum6.x常用语句
opencv 将16位图像数据转为8位、8转16
平台化,强链补链的一个支点
Greenplum6.x监控软件搭建
【微信小程序:缓存操作】
如何在HarmonyOS应用中集成App Linking服务
为什么要选择云原生数据库
idea里使用module项目的一个bug
Test pits - what test points should be paid attention to when adding fields to existing interfaces (or database tables)?
調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
[Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
Gson转换实体类为json时报declares multiple JSON fields named