-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy path0384.cpp
More file actions
27 lines (23 loc) · 671 Bytes
/
0384.cpp
File metadata and controls
27 lines (23 loc) · 671 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
class Solution {
public:
Solution(vector<int>& nums) { v.assign(nums.begin(), nums.end()); }
/** Resets the array to its original configuration and return it. */
vector<int> reset() { return v; }
/** Returns a random shuffling of the array. */
vector<int> shuffle() {
vector<int> res{v};
for (int i = 0; i < res.size(); ++i) {
int t = i + rand() % (res.size() - i);
swap(res[i], res[t]);
}
return res;
}
private:
vector<int> v;
};
/**
* 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();
*/