当前位置:网站首页>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);
*/
边栏推荐
- Leetcode 1984. Minimum difference in student scores
- JS的操作
- Tips for using jeditabletable
- Novice entry SCM must understand those things
- [MySQL] detailed explanation of trigger content of database advanced
- 南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案
- [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
- A single game with goods increased by 100000, and the rural anchor sold men's clothes on top of the list?
- How to realize sliding operation component in fast application
- ES6_ Arrow function
猜你喜欢

LeetCode 736. Lisp 语法解析

ncs成都新电面试经验
![[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

Category of IP address

leetcode134. gas station

Greenplum6.x常用语句

A single game with goods increased by 100000, and the rural anchor sold men's clothes on top of the list?
![Upload an e-office V9 arbitrary file [vulnerability recurrence practice]](/img/e7/278193cbc2a2f562270f99634225bc.jpg)
Upload an e-office V9 arbitrary file [vulnerability recurrence practice]

How to realize the high temperature alarm of the machine room in the moving ring monitoring system

Greenplum 6.x build_ Environment configuration
随机推荐
IP地址的类别
About using CDN based on Kangle and EP panel
Database storage - table partition
Three usage scenarios of annotation @configurationproperties
求有符号数的原码、反码和补码【C语言】
注解@ConfigurationProperties的三种使用场景
GoLand set goproxy
leetcode134. gas station
年薪50w阿里P8亲自下场,教你如何从测试进阶
NCS Chengdu New Electric interview Experience
Gson converts the entity class to JSON times declare multiple JSON fields named
opencv 将16位图像数据转为8位、8转16
Greenplum6.x监控软件搭建
Greenplum 6.x build_ install
opencv之图像分割
关于基于kangle和EP面板使用CDN
【MySQL】数据库进阶之触发器内容详解
調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
[machine learning] watermelon book data set_ data sharing
详解华为应用市场2022年逐步减少32位包体上架应用和策略