def merge(nums1, nums2):
    """
    Merge two given sorted arrays by merge sort

    :param nums1: first array
    :type nums1: list[int]
    :param nums2: second array
    :type nums2: list[int]
    :return: merged array
    :rtype: list[int]
    """
    result = []
    i = j = 0
    while i < len(nums1) and j < len(nums2):
        if nums1[i] < nums2[j]:
            result.append(nums1[i])
            i += 1
        else:
            result.append(nums2[j])
            j += 1
    while i < len(nums1):
        result.append(nums1[i])
        i += 1
    while j < len(nums2):
        result.append(nums2[j])
        j += 1
    return result