public void nextPermutation(int[] nums) { int i = nums.length -2; while(i>=0 && nums[i+1] <= nums[i]){ i--; } if(i>=0){ int j = nums.length -1; while(j>=0 && nums[j] <= nums[i]){ j--; } swap(nums,i,j); } reverse(nums,i+1); } public void swap(int[] nums, int i, int j){ int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } public void reverse(int[] nums, int start){ int i = start, j = nums.length -1; while(i < j){ swap(nums,i,j); i++; j--; } }
——2020.5.29
时隔一个多月再看,一点印象都没有。。。
——2020.7.9