Quickest, but least productive, solution to code


  • 0
    K

    While this would certainly not help in an interview, this can be solved with STL's own next_permutation :)

    class Solution {
    public:
        vector<vector<int>> permute(vector<int>& nums) 
        {
            vector<vector<int>> result;
            sort(nums.begin(), nums.end());
            do
            {
                result.push_back(nums);
            } while(next_permutation(nums.begin(), nums.end()));
            return result;
        }
    }
    

Log in to reply
 

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