当前位置:网站首页>710. random numbers in the blacklist
710. random numbers in the blacklist
2022-06-26 14:48:00 【anieoo】
Original link :710. Random numbers in the blacklist

solution:
The title requires that a random one be returned 0 ~ n - 1 Numbers not on the blacklist , So we can 0 ~ n - 1 Divide into two groups .
The first group is 0 ~ n - len - 1 and The second group n - len ~ n - 1 among len Indicates the number of numbers in the blacklist .
Use a hash table to create 0 ~ n - len - 1 In the blacklist count to n - len ~ n - 1 White list number mapping in .
class Solution {
public:
int n,len; //len Save the length of the blacklist
unordered_map<int,int> hash; //hash Storage 0~n - len - 1 Medium blacklist number pairs n - len ~ n White list mapping in
Solution(int _n, vector<int>& blacklist) {
n = _n;
len = blacklist.size();
unordered_set<int> s;
for(int i = n - len;i < n;i++) s.insert(i);
for(auto &x : blacklist) s.erase(x); // preservation n - len ~ n In the white list
// Building mapping
auto it = s.begin();
for (auto x: blacklist)
if (x < n - len)
hash[x] = *it ++ ;
}
int pick() {
int x = rand() % (n - len);
if(hash.count(x)) return hash[x];
return x;
}
};
/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(n, blacklist);
* int param_1 = obj->pick();
*/
边栏推荐
- datasets Dataset类(2)
- Leaflet loading ArcGIS for server map layers
- teamviewer显示设备数量上限解决方法
- NAACL2022:(代码实践)好的视觉引导促进更好的特征提取,多模态命名实体识别(附源代码下载)...
- Summary of decimal point of amount and price at work and pit
- Use abp Zero builds a third-party login module (II): server development
- Error when redis is started: could not create server TCP listening socket *: 6379: bind: address already in use - solution
- Unity uses skybox panoramic shader to make panorama preview. There is a gap. Solution
- 获取两个dataframe的交并差集
- Caelus - full scene offline mixed Department solution
猜你喜欢

Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)
![[cloud native] codeless IVX editor programmable by](/img/10/7c56e46df69be6be522a477b00ec05.png)
[cloud native] codeless IVX editor programmable by "everyone"

Server create virtual environment run code

ArcGIS batch export layer script

The engine "node" is inconsistent with this module

使用 Abp.Zero 搭建第三方登录模块(一):原理篇

From Celsius to the three arrows: encrypting the domino of the ten billion giants, and drying up the epic liquidity

印尼投资部长:鸿海考虑在其新首都建立电动公交系统、城市物联网

Chinese output of PostGIS console is garbled

The annual salary of 500000 is one line, and the annual salary of 1million is another line
随机推荐
View触摸分析
登录认证服务
【soloπ】adb连接单个多个手机
Server create virtual environment run code
wptx64能卸载吗_win10自带的软件哪些可以卸载
Introduction to basic knowledge of C language (Daquan) [suggestions collection]
NAACL2022:(代码实践)好的视觉引导促进更好的特征提取,多模态命名实体识别(附源代码下载)...
Practice with the topic of bit operation force deduction
MySQL master-slave replication and read-write separation
Question bank and answers of the latest Guizhou construction eight (Mechanics) simulated examination in 2022
The annual salary of 500000 is one line, and the annual salary of 1million is another line
扩展-Hooks
GDAL grid data types and their type codes
fileinput. js php,fileinput
Heap optimization dijkstra/hash table storage node number
Combat readiness mathematical modeling 32 correlation analysis 2
BM3D in popular language
Transformers datacollatorwithpadding class
Extended hooks
通俗语言说BM3D