-
Notifications
You must be signed in to change notification settings - Fork 0
/
201108-1.cpp
49 lines (43 loc) · 900 Bytes
/
201108-1.cpp
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
// https://leetcode-cn.com/problems/shuffle-an-array/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
Solution(vector<int>& nums) {
a = s = nums;
}
/** Resets the array to its original configuration and return it. */
vector<int> reset() {
return a;
}
/** Returns a random shuffling of the array. */
vector<int> shuffle() {
random_shuffle(s.begin(), s.end());
return s;
}
private:
vector<int> a;
vector<int> s;
};
void print(const vector<int>& a)
{
for (auto e : a) cout << e << " ";
cout << endl;
}
/**
* 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();
*/
int main()
{
vector<int> a{1,2,3};
Solution s(a);
print(s.shuffle());
print(s.reset());
print(s.shuffle());
return 0;
}