class Solution { public: vector<vector<int>> permutation(vector<int>& nums) { vector<vector<int>> res; //先从小到大 sort(nums.begin(),nums.end()); res.push_back(nums); int n = nums.size(); while(1){ int i = n-1; //找到一个后面比前面大的位置,说明还可以变大 while( i >= 1 &&nums[i] <= nums[i-1]) i--; if( i == 0) break; //在后面找大于nums【i-1】的最小值 int mm = i; for(int j = i; j < n; j++) if(nums[j] > nums[i-1] && nums[j] < nums[mm]) mm = j; //交换 swap(nums[i-1],nums[mm]); //后面的元素重新从小到大排序; sort(nums.begin()+i,nums.end()); res.push_back(nums); } return res; } };