package leetcode;

/**
 * https://leetcode.com/problems/next-permutation/
 */
public class Problem31 {
    public void nextPermutation(int[] nums) {
        //TODO
    }

    public static void main(String[] args) {
        Problem31 prob = new Problem31();
        // TODO
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -180,124 +180,679 @@
     
-//TODO%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem31 prob = new Problem31();%0A        // TODO
+for (int current = nums.length-2; current %3E= 0; current--) %7B%0A            if (nums%5Bcurrent%5D %3C nums%5Bcurrent+1%5D) %7B%0A                int val = nums%5Bcurrent%5D;%0A                Arrays.sort(nums, current, nums.length);%0A                int idx = Arrays.binarySearch(nums, current, nums.length, val);%0A                while (idx+1 %3C nums.length && nums%5Bidx+1%5D == val) %7B%0A                    idx++;%0A                %7D%0A                int tmp = nums%5Bidx+1%5D;%0A                for (int i = idx+1; i %3E= current+1; i--) %7B%0A                    nums%5Bi%5D = nums%5Bi-1%5D;%0A                %7D%0A                nums%5Bcurrent%5D = tmp;%0A                return;%0A            %7D%0A        %7D%0A        Arrays.sort(nums);
 %0A   

Solve problem 31