Use the function "STL next_permutation" to solve this problem. good or BAD???


  • 0
    Y
     vector<vector<int> > permute(vector<int> &num) {
        vector<vector<int> > p;
        if(num.size() == 0) return p;
        
        sort(num.begin(), num.end());
        do{
            p.push_back(num);
        }while(next_permutation(num.begin(), num.end()));
        
        return p;
    }

  • 3
    S

    Definitely raise this concern to your interviewer before answering the question. It is good only when your interviewer says so. However, it is verly likely that he or she will ask you to implement next_permutation all by yourself, so be prepared.


  • 0
    Y

    Thank you! I think so, too!!


  • 0
    S

    Permutation and Subset problems are the symbol of recursive problems in CS. Having a good knowledge of recursive solution for them would make you more like a Computer Scientist.

    Cheers


Log in to reply
 

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