题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/278419c1a3183efefa97e77f2da92c67.png)
Leetcode 384. 打乱数组
代码(9.11 首刷自解)
class Solution {
public:
vector<int> pre, cur;
Solution(vector<int>& nums) {
pre = nums;
cur = nums;
}
vector<int> reset() {
return pre;
}
vector<int> shuffle() {
for(int i = 0; i < cur.size(); i++) {
int pos = rand()%(cur.size());
swap(cur[i], cur[pos]);
}
return cur;
}
};