当前位置:网站首页>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);
*/
边栏推荐
- 【微信小程序:缓存操作】
- Count sort (diagram)
- FPGA knowledge accumulation [6]
- Input and output of floating point data (C language)
- [Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
- Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
- Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
- Go write a program that runs within a certain period of time
- [step on the pit] Nacos registration has been connected to localhost:8848, no available server
- Enterprise manager cannot connect to the database instance
猜你喜欢

NCS Chengdu Xindian interview experience

xray的简单使用
![[Yugong series] February 2022 U3D full stack class 005 unity engine view](/img/19/dc1b2f74b9ec5f5808de3049793862.jpg)
[Yugong series] February 2022 U3D full stack class 005 unity engine view
![[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

Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
![[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology](/img/2a/01db1b84c26502c851786aaca56abe.jpg)
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology

Pointer advanced, string function

Exercise arrangement 2.10, 11

Markdown编辑器Editor.md插件的使用
![[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
随机推荐
uniapp 微信小程序监测网络
Exercise arrangement 2.10, 11
路由信息协议——RIP
数据分析方法论与前人经验总结2【笔记干货】
Greenplum6.x重新初始化
Go write a program that runs within a certain period of time
NCS Chengdu Xindian interview experience
[machine learning] watermelon book data set_ data sharing
Required String parameter ‘XXX‘ is not present
Mock.js用法详解
[Yugong series] February 2022 U3D full stack class 006 unity toolbar
Laravel8 uses passport login and JWT (generate token)
Componentspace2022, assertions, protocols, bindings, and configuration files
9c09730c0eea36d495c3ff6efe3708d8
String operation
数据库存储---表分区
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
[Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
idea里使用module项目的一个bug
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error