Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int wlen;
- unordered_map<int, int> m;
- Solution(int n, vector<int>& blacklist) {
- wlen = n-blacklist.size();
- unordered_set<int> white;
- for(int i=wlen; i<n; i++) white.insert(i);
- for(int bnum : blacklist) white.erase(bnum);
- auto wi = white.begin();
- for(int bnum: blacklist){
- if(bnum < wlen)
- m[bnum] = *wi++;
- }
- }
- int pick() {
- int k = rand() % wlen;
- return m.count(k) ? m[k] : k;
- }
- };
- /**
- * Your Solution object will be instantiated and called as such:
- * Solution* obj = new Solution(n, blacklist);
- * int param_1 = obj->pick();
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement