Can I use next_permutation()???


  • 0

    If I use next_permutation(), the code will be so short...

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

Log in to reply
 

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