Created
October 27, 2016 17:27
-
-
Save qiuwch/1ea789f6d714d97ed0f2acea56826d41 to your computer and use it in GitHub Desktop.
C++ basics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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