-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShuffleArray.cpp
More file actions
33 lines (28 loc) · 796 Bytes
/
ShuffleArray.cpp
File metadata and controls
33 lines (28 loc) · 796 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
class Solution {
private:
vector<int> myNum;
public:
Solution(vector<int> nums) {
this->myNum = nums;
}
/** Resets the array to its original configuration and return it. */
vector<int> reset() {
return myNum;
}
/** Returns a random shuffling of the array. */
vector<int> shuffle() {
vector<int> sArray(myNum);
for (int i = 0; i < sArray.size(); i++)
{
int j = rand() % (sArray.size()-i);
swap(sArray[i+j], sArray[i]);
}
return sArray;
}
};
/**
* 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();
*/