Q: Why is this not accepted?


  • -1
    S

    Hi all,

    Can you please take a look at this and give me hint why this is not accepted? I got the idea from the permutation generation.

    vector<int> shuffle() {
        vector<int> shuffled(nums.size());
        for (int i = 0; i < nums.size(); i++) {
            shuffled[i] = rand() % ((int)nums.size() - i);
        }
        
        for (int i = 0; i < nums.size(); i++) {
            for (int j = i + 1; j < nums.size(); j++) {
                if (shuffled[j] >= shuffled[i]) {
                    shuffled[j]++;
                }
            }
        }
    
        for (int i = 0; i < nums.size(); i++) {
            shuffled[i] = nums[shuffled[i]];
        }
        
        return shuffled;
    }

Log in to reply
 

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