-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path384.cpp
More file actions
28 lines (24 loc) · 664 Bytes
/
Copy path384.cpp
File metadata and controls
28 lines (24 loc) · 664 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
// WTF.cpp
class Solution {
vector<int> arr;
public:
Solution(vector<int> nums) { arr = nums; }
/** Resets the array to its original configuration and return it. */
vector<int> reset() { return arr; }
/** Returns a random shuffling of the array. */
vector<int> shuffle() {
vector<int> result(arr);
int n = result.size();
for (int i = 0; i < n; i++) {
int pos = rand() % n;
swap(result[pos], result[i]);
}
return result;
}
};
/**
* Your Solution object will be instantiated and called as such:
* Solution obj = new Solution(nums);
* vector<int> param_1 = obj.reset();
* vector<int> param_2 = obj.shuffle();
*/