Why no one uses std::shuffle? 6 lines, AC and pretty fast, beats 77%


  • 0
    J
    class Solution {
        vector<int> arr, orig;
    
      public:
        Solution(vector<int> nums) : arr(nums), orig(nums) { srand(time(NULL)); }
    
        /** Resets the array to its original configuration and return it. */
        vector<int> reset() {
            arr = orig;
            return arr;
        }
    
        /** Returns a random shuffling of the array. */
        vector<int> shuffle() {
            std::shuffle(arr.begin(), arr.end(), rand());
            return arr;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.