当前位置:网站首页>2022.6.26-----leetcode. seven hundred and ten
2022.6.26-----leetcode. seven hundred and ten
2022-06-27 08:25:00 【Lu 727】
// take [0,n-m-1] Number of blacklists and [n−m,n-1] The white name singular of , Random return [0,n-m-1] Number in Li
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);
}边栏推荐
猜你喜欢
随机推荐
100% understanding of 5 IO models
【批处理DOS-CMD命令-汇总和小结】-环境变量、路径变量、搜索文件位置相关指令——set、path、where,cmd命令的路径参数中有空格怎么办
Coggle 30 days of ML July competition learning
[notes on c++ primer] Chapter 3 string, vector and array
Mysql-8 download, installation and configuration tutorial under Windows
MySQL environment variable configuration tutorial
0号进程,1号进程,2号进程
【批处理DOS-CMD命令-汇总和小结】-cmd的内部命令和外部命令怎么区分,CMD命令和运行(win+r)命令的区别,
淘宝虚拟产品开店教程之作图篇
Recognize the ordering of O (nlogn)
盲測調查顯示女碼農比男碼農更優秀
SPARQL basic introductory exercise
Read datasets iteratively with xgboost
Zabbix部署说明(Server+Win客户端+交换机(H3C))
(original) custom drawable
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
Lvgl description 3 about the use of lvgl Guide
【原创】TypeScript字符串utf-8编码解码
Blind survey shows that female code farmers are better than male code farmers
一种太阳能电荷泵供电电路的方案设计








