Binary Search:leetcode 4 Medium of two merged sorted array
The article explains how to implement binary search method to find the medium of two merged sorted array with the best approach.
Given two integers \(m\) 和 \(n\) with sorted arrays nums1
and nums2
。Please find the medium of the merged sorted array. The time complexity should be \(O(log (m+n))\) 。
Example 1:
1Input:nums1 = [1,3], nums2 = [2]
2Output:2.00000
3Explain:mergedArray = [1,2,3] ,medium = 2
Example 2:
1Input:nums1 = [1,2], nums2 = [3,4]
2Output:2.50000
3Explain:mergedArray = [1,2,3,4] ,medium = (2 + 3) / 2 = 2.5