easy understood c++ solution


  • -1
    A

    class Solution {
    public:
    Solution(vector<int> nums) {
    origin = nums;
    current = 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 len = current.size();
        for(int i = 0; i < len; i++)
        {
            int r = rand() % len;
            swap(current[i], current[r]);
        }
        return current;
    }
    

    private:
    vector<int> origin;
    vector<int> current;
    };


Log in to reply
 

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