extremely concise code, don't know why MLE

  • 0

    code is here

    class Solution {
        Solution(vector<int> nums) {
            for (int i = 0; i < nums.size(); ++i)
        int pick(int target) {
            return m[target][rand() % m[target].size()];
        unordered_map<int, vector<int>> m;

    passed all test case actually 13/13, but the last one the test case was [1,2,3,3,3] and just picked a whole bunch of 3s. i don't see how this case can cause MLE issue. at least it should be a huge one. just don't get it.. maybe leetcode just want you to use reservoir sampling. but i mean if you have lots of picks than building the object, then this is a better solution.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.