当前位置:网站首页>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);
*/
边栏推荐
- [Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
- 测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
- [Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
- Uniapp wechat applet monitoring network
- RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
- 数字三角形模型 AcWing 1027. 方格取数
- 实现自定义内存分配器
- Why choose cloud native database
- All about PDF crack, a complete solution to meet all your PDF needs
- 如何在HarmonyOS应用中集成App Linking服务
猜你喜欢

Componentspace2022, assertions, protocols, bindings, and configuration files
![Upload an e-office V9 arbitrary file [vulnerability recurrence practice]](/img/e7/278193cbc2a2f562270f99634225bc.jpg)
Upload an e-office V9 arbitrary file [vulnerability recurrence practice]

JS operation
![[MySQL] detailed explanation of trigger content of database advanced](/img/6c/8aad649e4ba1160db3aea857ecf4a1.png)
[MySQL] detailed explanation of trigger content of database advanced
![[step on the pit] Nacos registration has been connected to localhost:8848, no available server](/img/ee/ab4d62745929acec2f5ba57155b3fa.png)
[step on the pit] Nacos registration has been connected to localhost:8848, no available server

Quick sorting (detailed illustration of single way, double way, three way)
![[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University](/img/e2/519a5267cd5425a83434d2da65ebe6.jpg)
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University

let const

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

如何在HarmonyOS应用中集成App Linking服务
随机推荐
leetcode134. gas station
阿里p8手把手教你,自动化测试应该如何实现多线程?赶紧码住
[Yugong series] February 2022 U3D full stack class 008 - build a galaxy scene
Image segmentation in opencv
测试踩坑 - 当已有接口(或数据库表中)新增字段时,都需要注意哪些测试点?
Why choose cloud native database
【踩坑】nacos注册一直连接localhost:8848,no available server
快速集成认证服务-HarmonyOS平台
Data type - integer (C language)
Frequently Asked Coding Problems
go写一个在一定时间内运行的程序
oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
Golan idea IntelliJ cannot input Chinese characters
LeetCode 715. Range 模块
Problems encountered in the use of go micro
JEditableTable的使用技巧
联想混合云Lenovo xCloud:4大产品线+IT服务门户
Input and output of floating point data (C language)
Category of IP address
如何在HarmonyOS应用中集成App Linking服务