当前位置:网站首页>leetcode - 384. Scramble array

leetcode - 384. Scramble array

2022-06-25 12:58:00 zmm_ mohua

leetcode - 384. Scramble the array

subject

 Insert picture description here

Code

#include <iostream>
#include <vector>
using namespace std;

vector<int> nums;
vector<int> original;

Solution(vector<int>& nums) {
    
	this->nums = nums;
	this->original.resize(nums.size());
	copy(nums.begin(), nums.end(), original.begin());
}
    
vector<int> reset() {
    
	copy(original.begin(), original.end(), nums.begin());
	return nums;
}
    
vector<int> shuffle() {
    
	for(int i = 0; i < nums.size(); i++){
    
		int j = i + rand() % (nums.size() - i);
		swap(nums[i], nums[j]);
	}
	return nums;
}

int main(){
    
	
	return 0;
}
原网站

版权声明
本文为[zmm_ mohua]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251219488956.html