public void nextPermutation(int[] nums) {
        if(nums.length <= 1) {
            return;
        }

        int i = nums.length - 2;
        for(; i >= 0; i--) {
            if(nums[i+1] > nums[i]) {
                break;
            }
        }

        if(i == -1) {
            reverse(nums, 0, nums.length-1);
            return;
        }

        for(int j = nums.length-1; j > i; j--) {
            if(nums[j] > nums[i]) {
                swap(nums, i, j);
                break;
            }
        }

        reverse(nums, i+1, nums.length-1);

    }