当前位置:网站首页>2022.6.26-----leetcode.710
2022.6.26-----leetcode.710
2022-06-27 08:11:00 【路Lu727】
//将[0,n-m-1]的黑名单数与[n−m,n-1]的白名单数进行映射,随机返回[0,n-m-1]里的数
Map<Integer, Integer> b2w;
Random random;
int bound;
public Solution(int n, int[] blacklist) {
b2w = new HashMap<Integer, Integer>();
random = new Random();
int m = blacklist.length;
bound = n - m;
Set<Integer> black = new HashSet<Integer>();
for (int b : blacklist) {
if (b >= bound) {
black.add(b);
}
}
int w = bound;
for (int b : blacklist) {
if (b < bound) {
while (black.contains(w)) {
++w;
}
b2w.put(b, w);
++w;
}
}
}
public int pick() {
int x = random.nextInt(bound);
return b2w.getOrDefault(x, x);
}边栏推荐
- (note) Anaconda navigator flashback solution
- L'enquête en aveugle a montré que les femmes étaient meilleures que les hommes.
- 参考 | Win11 开启热点之后电脑不能上网
- JS uses the while cycle to calculate how many years it will take to grow from 1000 yuan to 5000 yuan if the interest rate for many years of investment is 5%
- [paper reading] internally semi supervised methods
- 关于el-date-picker点击清空参数变为null的问题
- Eight misunderstandings, broken one by one (final): the cloud is difficult to expand, the customization is poor, and the administrator will lose control?
- Lvgl usage demo and instructions 2
- Blind survey shows that female code farmers are better than male code farmers
- [12. maximum continuous non repeating subsequence]
猜你喜欢

05 观察者(Observer)模式

SIG associé: toutes les routes mènent à ue5
![[10. difference]](/img/15/ffd93da75858943fe887de1718e0f6.png)
[10. difference]

C how to call line and rows when updating the database

Read datasets iteratively with xgboost

Index +sql exercise optimization

Redis installation under Linux

无论LCD和OLED显示技术有多好,都无法替代这个古老的显示数码管

After working in a large factory for ten years with an annual salary of 400000 yuan, I was suddenly laid off. If the company wanted to abandon you, it wouldn't leave any kindness
![【批处理DOS-CMD命令-汇总和小结】-批处理命令中的参数%0、%1、%2、%[0-9]、%0-9和批处理命令参数位置切换命令shift,dos命令中操作符%用法](/img/05/19299c47d54d4ede95322b5a923093.png)
【批处理DOS-CMD命令-汇总和小结】-批处理命令中的参数%0、%1、%2、%[0-9]、%0-9和批处理命令参数位置切换命令shift,dos命令中操作符%用法
随机推荐
What is futures reverse documentary?
Five basic types of redis
若xn>0,且x(n+1)/xn>1-1/n(n=1,2,...),证明级数∑xn发散
PayPal account has been massively frozen! How can cross-border sellers help themselves?
DataV轮播表组件dv-scroll-board宽度问题
Blind survey shows that female code farmers are better than male code farmers
Redis transactions
关于放大器失真的原因你了解多少呢?
March into machine learning -- Preface
准备好迁移上云了?请收下这份迁移步骤清单
c#的初步认识
【原创】TypeScript字符串utf-8编码解码
Game asset reuse: a new way to find required game assets faster
關聯GIS:條條道路通UE5城
爬一个网页的所有导师信息
Persistence mechanism of redis
Etcd教程 — 第五章 Etcd之etcdctl的使用
野風藥業IPO被終止:曾擬募資5.4億 實控人俞蘠曾進行P2P投資
洛谷刷题心得记录
Install Jenkins