打乱数组
class Solution {
private int nums[];
private Random random;
public Solution(int[] nums) {
this.nums = nums;
random = new Random();
}
public int[] reset() {
return nums;
}
public int[] shuffle() {
int temp[] = Arrays.copyOf(nums, nums.length);
for(int i = 0; i < nums.length; i++){
int index = random.nextInt(nums.length - i) + i;
int swap = temp[index];
temp[index] = temp[i];
temp[i] = swap;
}
return temp;
}
}
/**
* Your Solution object will be instantiated and called as such:
* Solution obj = new Solution(nums);
* int[] param_1 = obj.reset();
* int[] param_2 = obj.shuffle();
*/