-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path384.java
More file actions
33 lines (28 loc) · 739 Bytes
/
384.java
File metadata and controls
33 lines (28 loc) · 739 Bytes
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
import java.util.Random;
class Solution {
int[] data;
Random rand;
public Solution(int[] nums) {
data = nums;
rand = new Random();
}
public int[] reset() {
return data;
}
public int[] shuffle() {
int[] shuffled = data.clone();
for (int i=shuffled.length-1;i>0;i--) {
int j = rand.nextInt(i+1);
int temp = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = temp;
}
return shuffled;
}
}
/**
* 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();
*/