描述
按照要求实现函数
解决
class Solution {
public:
Solution(vector<int> nums) {
int length = nums.size();
tmp.resize(length);
zz.resize(length);
tmp = nums;
zz = nums;
}
/** Resets the array to its original configuration and return it. */
vector<int> reset() {
return zz;
}
/** Returns a random shuffling of the array. */
vector<int> shuffle() {
int length = tmp.size();
for (int i = 0; i < length; ++i)
{
swap(tmp[i], tmp[rand() % (i + 1)]);
}
return tmp;
}
vector<int> tmp, zz;
};
/**
* 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();
*/