当前位置:网站首页>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;
}
};
边栏推荐
- laravel中使用group by分组并查询数量
- 杜比全景音效简介
- 机器学习PCA——实验报告
- 动态规划解决股票问题(下)
- Redis best practices? If I don't feel excited after reading it, I will lose!!
- 2、 Linear table
- APICloud 实现文档下载和预览功能
- Laravel writes native SQL statements
- How does unity prevent other camera positions and rotations from being controlled by steamvrplugin when using steamvrplugin
- laravel-admin隐藏按钮, 及设置按钮显示, 默认序列, form 表单的不可修改值
猜你喜欢

Machine learning deep neural network -- Experimental Report

Sqli-labs靶场1-5

【深度学习理论】(7) 长短时记忆网络 LSTM

统计遗传学:第一章,基因组基础概念

redux相关用法

.net中,日志组件 Nlog,SerialLog, Log4Net的用法

深度理解STM32的串口實驗(寄存器)【保姆級教程】

Mqtt disconnect and reconnect

How does unity prevent other camera positions and rotations from being controlled by steamvrplugin when using steamvrplugin

Origin of b+ tree index
随机推荐
量化初级 -- akshare获得股票代码,最简策略
Compréhension approfondie de l'expérience de port série stm32 (registre) [Tutoriel de niveau nounou]
Is it safe to open an account in the top ten securities app rankings in China
统计遗传学:第二章,统计分析概念
【北邮果园微处理器设计】10 Serial Communication 串口通信笔记
Laravel-admin 登录添加图形验证码
2021 Q3-Q4 Kotlin Multiplatform 使用现状 | 调查报告
Consumer microservice Governance Center stepping on the pit
Openresty overview
[deep learning theory] (7) long and short term memory network LSTM
哈希表的前置知识---二叉搜索树
深圳市福田区支持文化创意产业发展若干措施
Dynamic programming to solve stock problems (Part 2)
I want to know whether flush is a stock market? Is it safe to open a mobile account?
TCP面试
Uncaught reflectionexception: class view does not exist
FastRCNN
redux相关用法
【深度学习理论】(7) 长短时记忆网络 LSTM
深度理解STM32的串口實驗(寄存器)【保姆級教程】