public void merge(int[] nums, int begin, int mid, int end) {
        int[] left = new int[mid - begin];
        int[] right = new int[end - mid + 1];
        for (int i = 0; i < left.length; ++i) {
            left[i] = nums[begin + i];
        }
        for (int i = 0; i < right.length; ++i) {
            right[i] = nums[mid + i];
        }
        int i = 0, j = 0, index = begin;
        while (i < left.length && j < right.length) {
            if (left[i] < right[j]) {
                nums[index++] = left[i++];
            } else {
                nums[index++] = right[j++];
            }
        }
        while (i < left.length) {
            nums[index++] = left[i++];
        }
        while (j < right.length) {
            nums[index++] = right[j++];
        }
    }