-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path710.cpp
More file actions
30 lines (28 loc) · 766 Bytes
/
710.cpp
File metadata and controls
30 lines (28 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public:
unordered_map<int, int> mp;
set<int> st;
int validSize = 0;
Solution(int n, vector<int>& blacklist) {
validSize = n - blacklist.size();
int idx = validSize;
for (auto& num : blacklist) st.insert(num);
for (auto& num : st) {
if (num < validSize) {
while (st.find(idx) != st.end()) idx++;
mp[num] = idx;
idx++;
}
}
}
int pick() {
int rnd = rand() % validSize;
if (mp.find(rnd) != mp.end()) return mp[rnd];
return rnd;
}
};
/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(n, blacklist);
* int param_1 = obj->pick();
*/