class Solution {
int[] nums;
int[] backNums; // 数组备份
public Solution(int[] nums) {
this.nums = nums;
backNums = nums.clone();
}
/**
* Resets the array to its original configuration and return it.
*/
public int[] reset() {
nums = backNums.clone();
return nums;
}
/**
* Returns a random shuffling of the array.
*/
public int[] shuffle() {
int n = nums.length;
Random random = new Random();
for (int i = 0; i < n; i++) {
int p = random.nextInt(n);
int temp = nums[i];
nums[i] = nums[p];
nums[p] = temp;
}
return nums;
}
}
/**
* 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();
*/