Java Solution using a HashMap
Code\n\nclass Solution {\n    HashMap<Integer, Integer> blacklistMap;\n    int whiteSize;\n    public Solution(int n, int[] blacklist) {\n        blacklistMap =
# Code\n```\nclass Solution {\n    HashMap<Integer, Integer> blacklistMap;\n    int whiteSize;\n    public Solution(int n, int[] blacklist) {\n        blacklistMap = new HashMap<>();\n        whiteSize = n - blacklist.length;\n\n        for(int b: blacklist) {\n            blacklistMap.put(b, -1);\n        }\n        //\u5C06whitesize\u8303\u56F4\u91CC\u7684\u9ED1\u540D\u5355\u6620\u5C04\u5230whitesize\u4E4B\u540E\u7684\u767D\u540D\u5355\n        int last = n - 1;\n        for(int b: blacklist) {\n            if(b < whiteSize) {\n                while(blacklistMap.containsKey(last)) {\n                    last--;\n                }\n                blacklistMap.put(b, last);\n                last--;\n            }\n        }\n\n    }\n    \n    public int pick() {\n        int rand = (int)(Math.random() * whiteSize);\n        if(blacklistMap.containsKey(rand)) {\n            return blacklistMap.get(rand);\n        }\n        return rand;\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```
['Java']