5 lines solution in C++


  • 0
    S
    vector<vector<int>> permute( vector<int> &nums ) {
        std::sort( nums.begin(), nums.end() );
        vector<vector<int>> result{ nums };
        while( std::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.