-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path384.cpp
More file actions
executable file
·41 lines (37 loc) · 1.08 KB
/
384.cpp
File metadata and controls
executable file
·41 lines (37 loc) · 1.08 KB
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
class Solution {
public:
Solution(vector<int>& nums) {
original = nums;
}
/** Resets the array to its original configuration and return it. */
vector<int> reset() {
srand((unsigned)time(NULL));
return original;
}
/** Returns a random shuffling of the array. */
vector<int> shuffle() {
vector<int> res;
vector<int> choose;
for (int i = 0; i < original.size(); i++)
choose.push_back(i);
int length = original.size();
srand((unsigned)time(NULL));
sleep(100);
for (int i = 0; i < original.size(); i++){
int cur = rand() % length;
res.push_back(original[choose[cur]]);
if (cur != length - 1)
swap(choose[cur],choose[length - 1]);
length --;
}
return res;
}
private:
vector<int> original;
};
/**
* 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();
*/