-
Notifications
You must be signed in to change notification settings - Fork 0
/
384.java
37 lines (34 loc) · 950 Bytes
/
384.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class Solution {
int [] nums;
int [] s;
public Solution(int[] nums) {
this.nums = nums;
this.s = new int[nums.length];
for(int i =0; i<nums.length; ++i) {
s[i] = nums[i];
}
}
/** Resets the array to its original configuration and return it. */
public int[] reset() {
for(int i=0; i<s.length; ++i)
s[i] = nums[i];
return nums;
}
/** Returns a random shuffling of the array. */
public int[] shuffle() {
Random rand = new Random();
for(int i = nums.length - 1; i >= 1 ; i--) {
int r = rand.nextInt(i + 1);
int temp = s[i];
s[i] = s[r];
s[r] = temp;
}
return s;
}
}
/**
* 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();
*/