当前位置:网站首页>Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding
Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding
2022-06-26 11:20:00 【HERODING23】

Their thinking :
Realization [0,n-m] Interval blacklist pair [n-m, n] Non blacklist mapping of , And then take [0,n-m] random number , If it is a white list, return directly , Otherwise, the mapped white name singular number is returned , The code is as follows :
class Solution {
unordered_map<int, int> b2w;
int bound;
public:
Solution(int n, vector<int> &blacklist) {
int m = blacklist.size();
bound = n - m;
unordered_set<int> black;
for (int b: blacklist) {
if (b >= bound) {
black.emplace(b);
}
}
int w = bound;
for (int b: blacklist) {
if (b < bound) {
while (black.count(w)) {
++w;
}
b2w[b] = w++;
}
}
}
int pick() {
int x = rand() % bound;
return b2w.count(x) ? b2w[x] : x;
}
};
边栏推荐
- 科技兴关,荣联与天津海关共建基因组数据库及分析平台
- 【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
- JWT certification agreement -- I opened a Yihong hospital
- Dynamic programming to solve stock problems (Part 2)
- FastRCNN
- Mqtt disconnect and reconnect
- 24 个必须掌握的数据库面试问题!
- 我想知道同花顺是炒股的么?手机开户安全么?
- This paper introduces the simple operation of realizing linear quadratic moving average of time series prediction that may be used in modeling and excel
- Machine learning SVM - Experimental Report
猜你喜欢

PC qq Hall upload Update Modifying versioninfo

QT连接MySql数据查询失败

Origin of b+ tree index

Docker中实现MySQL主从复制

April 13, 2021 interview with beaver family

Easyx----- C language implementation 2048

MQTT断开重连

(Typora图床)阿里云oss搭建图床+Picgo上传图片详细教程

Qixia housing and Urban Rural Development Bureau and fire rescue brigade carried out fire safety training

This paper introduces the simple operation of realizing linear quadratic moving average of time series prediction that may be used in modeling and excel
随机推荐
4、 Stacks and queues
Recent work report
基于slate构建文档编辑器
matlab 编程实例: 如何统计元胞数组中元素的数量
Group by is used in laravel to group and query the quantity
有手就行的移动平均法、指数平滑法的Excel操作,用来时间序列预测
MQTT断开重连
深圳市福田区支持文化创意产业发展若干措施
ACK攻击是什么意思?ACK攻击怎么防御?
FasterRCNN
c语言 --- 运算符和表达式
哈希表的前置知识---二叉搜索树
Solidworks渲染技巧如何不显示边线--显示样式设定
MySQL Performance Monitoring and SQL statements
FasterRCNN
Excel operation of manual moving average method and exponential smoothing method for time series prediction
Is it safe for compass software to buy stocks for trading? How to open an account to buy shares
杜比全景音效简介
10年程序员职业生涯感悟—写给正在迷茫的你
Flannel's host GW and calico