Skip to content

Instantly share code, notes, and snippets.

@qiuwch
Created October 27, 2016 17:27
Show Gist options
  • Select an option

  • Save qiuwch/1ea789f6d714d97ed0f2acea56826d41 to your computer and use it in GitHub Desktop.

Select an option

Save qiuwch/1ea789f6d714d97ed0f2acea56826d41 to your computer and use it in GitHub Desktop.
C++ basics
class Solution {
vector<int> a;
public:
Solution(vector<int> nums) : a(nums) {}
/** Resets the array to its original configuration and return it. */
vector<int> reset() { return a; }
/** Returns a random shuffling of the array. */
vector<int> shuffle() {
auto r = a;
for (size_t i = 1; i < r.size(); i++)
swap(r[rand()%(i+1)], r[i]);
return r;
}
};
vector<int> input;
Solution a(input);
vector<int> v1 = a.reset();
vector<int> v2 = a.shuffle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment