710题解
Intuition\n Describe your first thoughts on how to solve this problem. \n\u5173\u952E\u662F\u4F1A\u62A5MLE,\u6240\u4EE5\u53EA\u80FD\u7528\u6620\u5C04\u7684\u529
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\u5173\u952E\u662F\u4F1A\u62A5MLE,\u6240\u4EE5\u53EA\u80FD\u7528\u6620\u5C04\u7684\u529E\u6CD5\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/*\n * @lc app=leetcode.cn id=710 lang=cpp\n *\n * [710] \u9ED1\u540D\u5355\u4E2D\u7684\u968F\u673A\u6570\n */\n\n// @lc code=start\n#include<bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n    int sz;\n    unordered_map<int,int> map;\n    Solution(int n, vector<int>& blacklist) {\n        sz = n-blacklist.size();\n        int last = n-1;\n        for(int b:blacklist) map[b] = 666;\n        for(int b:blacklist){\n            if(b>=sz) continue;\n            while(map.count(last)) last--;\n            map[b] = last;\n            last--;  \n        }\n    }\n    \n    int pick() {\n        int tmp = rand()%sz;\n        if(map.count(tmp)){\n            return map[tmp];\n        }\n        return tmp;\n    }\n};\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution* obj = new Solution(n, blacklist);\n * int param_1 = obj->pick();\n */\n// @lc code=end\n\n\n```
['C++']