This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public void nextPermutation(int[] nums) { | |
| // find the pivot from where the left part is in descending order | |
| for(int i = nums.length-2; i>=0; i--){ | |
| if(nums[i] < nums[i+1]){ | |
| int pivot = i; | |
| // now find successor of pivot from rightmost part | |
| int successor = nums.length-1; | |
| for(int j = nums.length-1; j>pivot; j--){ | |
| if(nums[j] > nums[pivot]){ |