private void nextPermutation(int[] num) {
        if (num.length == 1) return;
        int i = num.length - 2;
        for (; i >= 0; i--) {
            if (num[i] < num[i + 1])
                break;
            if (i == 0) {
                Arrays.sort(num);
                return;
            }
        }
        int closebig = num[i] + 1000000, indexbig = i;
        for (int j = i + 1; j < num.length; j++)
            if (num[j] < closebig && num[j] > num[i]) {
                closebig = num[j];
                indexbig = j;
            }
        int tmp = num[indexbig];
        num[indexbig] = num[i];
        num[i] = tmp;
        Arrays.sort(num, i + 1, num.length);
    }