Coding Round 2
Mid-Level
programming
LeetCode #4 - Median of Two Sorted Arrays
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log(min(m,n))). For example, given nums1 = [1, 3] and nums2 = [2], the median is 2.0. You need to implement the function
Example 1:
Input: nums1 = [1, 3], nums2 = [2]
Output: 2.00000
Example 2:
Input: nums1 = [1, 2], nums2 = [3, 4]
Output: 2.50000
Explanation: The median is (2 + 3)/2 = 2.5.
Constraints:
m == nums1.length, n == nums2.length
0 <= m <= 1000
0 <= n <= 1000
-10^6 <= nums1[i], nums2[i] <= 10^6.
double findMedianSortedArrays(int[] nums1, int[] nums2) that returns this value.Example 1:
Input: nums1 = [1, 3], nums2 = [2]
Output: 2.00000
Example 2:
Input: nums1 = [1, 2], nums2 = [3, 4]
Output: 2.50000
Explanation: The median is (2 + 3)/2 = 2.5.
Constraints:
m == nums1.length, n == nums2.length
0 <= m <= 1000
0 <= n <= 1000
-10^6 <= nums1[i], nums2[i] <= 10^6.
Suggested Answer