[go: nahoru, domu]

Skip to content

Commit

Permalink
add0384
Browse files Browse the repository at this point in the history
  • Loading branch information
lzyrapx committed Aug 7, 2020
1 parent 207231c commit 6530963
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions LeetCode/Medium/0384.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Solution {
public:
Solution(vector<int>& nums) {
elements = nums;
}

/** Resets the array to its original configuration and return it. */
vector<int> reset() {
return elements;
}

/** Returns a random shuffling of the array. */
vector<int> shuffle() {
vector<int> ans = elements;
for(int i = 0; i < ans.size(); i++) {
int r = rand() % (i + 1);
if(r != i) {
swap(ans[r], ans[i]);
}
}
return ans;
}
private:
vector<int>elements;
};

/**
* 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();
*/

0 comments on commit 6530963

Please sign in to comment.