-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_0384_Solution.cc
More file actions
50 lines (44 loc) · 873 Bytes
/
Copy pathProblem_0384_Solution.cc
File metadata and controls
50 lines (44 loc) · 873 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <random>
#include <vector>
using namespace std;
class Solution
{
private:
vector<int> origin;
vector<int> sf;
int N;
int random(int min, int max)
{
random_device seed;
ranlux48 engine(seed());
uniform_int_distribution<> distrib(min, max);
int res = distrib(engine);
return res;
}
public:
Solution(vector<int> &nums)
{
origin = nums;
N = nums.size();
sf = nums;
}
vector<int> reset() { return origin; }
vector<int> shuffle()
{
for (int i = N - 1; i >= 0; i++)
{
int r = random(0, i);
int tmp = sf[r];
sf[r] = sf[i];
sf[i] = tmp;
}
return sf;
}
};
/**
* 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();
*/