C++ Easy Solution (using STL) Few Lines


  • 0

    Using next Permutation STL:

    class Solution {
    public:
        vector<int> origin;
        vector<int> back;     //back to original
        Solution(vector<int> nums) {
            
            back=nums;
            origin=nums;
          
        }
        
        /** Resets the array to its original configuration and return it. */
        vector<int> reset() {
            
            return back;
            
        }
        
        /** Returns a random shuffling of the array. */
        vector<int> shuffle() {
            
            next_permutation(origin.begin(),origin.end());
            return origin;
            
        }
    };
    

Log in to reply
 

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