如何在由a和b合并后的已排序数组中找到中间元素?
Example:
n = 4
a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
merged = [1, 2, 3, 3, 4, 4, 5, 6]
mid_element = merged[(0 + merged.length - 1) / 2] = merged[3] = 3
更复杂的案例:
案例1:
a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
案例二:
a = [1, 2, 3, 4, 8]
b = [3, 4, 5, 6, 7]
第三种情况:
a = [1, 2, 3, 4, 8]
b = [0, 4, 5, 6, 7]
案例4:
a = [1, 3, 5, 7]
b = [2, 4, 6, 8]
时间复杂度为O(log n)。有什么想法吗?