Simple, Easy-to-Understand C++ Solution


  • 1
    A


    class Solution {
    public:
    Solution(vector<int> nums) {
    srand(time(NULL));
    curr=nums;
    }

    vector<int> reset() {
        return curr;
    }
    
    vector<int> shuffle() {
        vector<int> ret = curr;
        for(int size=curr.size();size>1;size--){
            int randIndex = rand() % size;
            swap(ret[randIndex], ret[size-1]);
        }
        return ret;
    }
    
    private:
    vector<int> curr;
    };

Log in to reply
 

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