Javascript solution


  • 0
    B
    var Solution = function(nums) {
        this.nums = nums || [];
    };
    
    Solution.prototype.reset = function() {
        return this.nums;
    };
    
    Solution.prototype.shuffle = function() {
        var arr = this.nums.slice();
        var counter = arr.length;
        var rand, tmp;
        
        while(counter > 0){
            rand = Math.floor(Math.random() * counter--);
            
            tmp = arr[counter];
            arr[counter] = arr[rand];
            arr[rand] = tmp;
        }
        return arr;
    };
    

Log in to reply
 

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