当前位置:网站首页>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);
*/
边栏推荐
- Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
- ES6_ Arrow function
- Greenplum 6.x version change record common manual
- [Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
- About using CDN based on Kangle and EP panel
- Arm GIC (IV) GIC V3 register class analysis notes.
- go写一个在一定时间内运行的程序
- A bug using module project in idea
- mysql分区讲解及操作语句
- Qt Charts使用(重写QChartView,实现一些自定义功能)
猜你喜欢
平台化,强链补链的一个支点
Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and
Greenplum6.x搭建_安装
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
Laravel8 uses passport login and JWT (generate token)
南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案
联想混合云Lenovo xCloud:4大产品线+IT服务门户
Data analysis methodology and previous experience summary 2 [notes dry goods]
[Nanjing University] - [software analysis] course learning notes (I) -introduction
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
随机推荐
Pointer advanced, string function
IP地址的类别
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
ncs成都新電面試經驗
[wechat applet: cache operation]
[Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
实现自定义内存分配器
Routing information protocol rip
All about PDF crack, a complete solution to meet all your PDF needs
Greenplum 6.x build_ install
[machine learning] watermelon book data set_ data sharing
Rapid integration of authentication services - harmonyos platform
idea里使用module项目的一个bug
JS operation
Basic data types and string types are converted to each other
Novice entry SCM must understand those things
[南京大学]-[软件分析]课程学习笔记(一)-introduction
A bug using module project in idea
Mock. JS usage details