C++ solution


  • 1
    D
    class Solution {
    public:
        Solution(vector<int> nums) {
            origin = nums;
            shuf = nums;
        }
        
        /** Resets the array to its original configuration and return it. */
        vector<int> reset() {
            return origin;
        }
        
        /** Returns a random shuffling of the array. */
        vector<int> shuffle() {
            int size = shuf.size();
            while(size) {
                int idx = rand() % size;
                swap(shuf[idx], shuf[--size]);
            }
            return shuf;
        }
    private:
        vector<int> origin;
        vector<int> shuf;
    };
    

Log in to reply
 

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