Posted on

Description

Submission

class Solution {
    vector<int>& original;
    vector<int> nums;
public:
    Solution(vector<int>& nums) 
        :
        original(nums),
        nums(nums)
    {}
    
    vector<int> reset() {
        nums = original;
        return nums;
    }
    
    vector<int> shuffle() {
        int n = nums.size();
        vector<int> rets(n);

        for(int i = 0; i < n; ++i) {
            int j = i + rand() % (nums.size() - i);
            swap(nums[i], nums[j]);
        }
        return nums;
    }
};

/**
 * Your Solution object will be instantiated and called as such:
 * Solution* obj = new Solution(nums);
 * vector<int> param_1 = obj->reset();
 * vector<int> param_2 = obj->shuffle();
 */

Leave a Reply

Your email address will not be published. Required fields are marked *