My Concise solution using STL C++ 12ms


  • -4
    S
       class Solution {
       public:
        vector<vector<int>> permute(vector<int>& nums) {
            sort(nums.begin(),nums.end());
            vector<vector<int>> ans;
            ans.push_back(nums);
            while(next_permutation(nums.begin(), nums.end())){
                ans.push_back(nums);
            }
            return ans;
        }
    };

Log in to reply
 

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