public void nextPermutation(int[] nums) {
        int i = nums.length - 1;
        while (i > 0) {
            if (nums[i - 1] < nums[i]) {
                break;
            } else
                --i;
        }
        if (i == 0) {
            Arrays.sort(nums);
            return;
        }
        // we find the i - 1, next, we need to change number between i and n-1
        int position = nums.length - 1;
        while (position > i - 1) {
            if (nums[position] > nums[i - 1]) {
                int temp = nums[position];
                nums[position] = nums[i - 1];
                nums[i - 1] = temp;
                break;
            }
            --position;
        }
        Arrays.sort(nums, i, nums.length);
    }