public void nextPermutation(int[] num) {
        if(num.length == 0 || num.length == 1) return;

        int i = num.length - 2;
        while(i >= 0 && num[i] >= num[i + 1]) i--;
        if(i < 0){
            reverse(num, 0, num.length - 1);
        }else{
            int partitionNum = num[i];
            int j = num.length - 1;
            while(j >= 0 && num[j] <= partitionNum) j--;
            swap(num, i, j);
            reverse(num, i + 1, num.length - 1);
        }
    }