Simple solution by using STL


  • 0
    J
    vector<vector<int> > permute(vector<int> &num)
    {
        sort(num.begin(), num.end());
        vector<vector<int> > rst(1, num);
    
        //get the next array by lexicographical order
        while (next_permutation(num.begin(), num.end()))    
        {
            rst.push_back(num);
        }
    
        return rst;
    }

Log in to reply
 

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