下一个排列
作者:互联网
class Solution { public: void nextPermutation(vector<int>& nums) { if(nums.size()<=1) return; int i=nums.size()-2; while(i>=0 && nums[i]>=nums[i+1]){ i-=1; } if(i==-1){ reverse(nums.begin(),nums.end()); return; } int j=nums.size()-1; while(j>=0 && nums[j]<=nums[i]){ j-=1; } int tmp=nums[i]; nums[i]=nums[j]; nums[j]=tmp; reverse(nums.begin()+i+1,nums.end()); return; } };
标签:begin,排列,end,nums,一个,nextPermutation,&&,size 来源: https://www.cnblogs.com/zijidan/p/12435818.html