下一个排列
- public class Solution {
- /**
- * @param nums: an array of integers
- * @return: return nothing (void), do not return anything, modify nums in-place instead
- */
- public void nextPermutation(int[] nums) {
- // write your code here
- int n = nums.length;
- for(int i=n-1;i>=0;i--)
- {
- for(int j=n-1;j>i;j--)
- {
- if(nums[i]<nums[j])
- {
- int tmp = nums[i];
- nums[i] = nums[j];
- nums[j] = tmp;
- Arrays.sort(nums,i+1,nums.length);
- return;
- }
- }
- }
- Arrays.sort(nums);
- }
- }