private int[] merge(int[] left, int[] right) {
        int[] result = new int[left.length + right.length];

        int i = 0, j = 0, k = 0;

        while (i < left.length && j < right.length) {
            if(left[i] < right[j]) result[k] = left[i++];
            else result[k] = right[j++];
            k++;
        }

        if(i == left.length) {
            for (; j < right.length; j++) {
                result[k++] = right[j];
            }
        }

        if(j == right.length) {
            for (; i < left.length; i++) {
                result[k++] = left[i];
            }
        }

        return result;
    }