5 line cheating none-recursion C++ solution :)


  • -2
    W
    vector<vector<int>> permute(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        vector<vector<int>> result { nums };
        while (next_permutation(nums.begin(), nums.end()))
            result.push_back(nums);
        return result;
    }

Log in to reply
 

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