Given two sorted arrays `nums1` and `nums2` of sizes m and n respectively, return the median of the two sorted arrays combined. The median is the middle value when all elements are arranged in order. If the total number of elements is even, the median is the average of the two middle values. For example, given nums1 = [1,3] and nums2 = [2], the merged array is [1,2,3] and the median is 2.0. Given nums1 = [1,2] and nums2 = [3,4], the merged array is [1,2,3,4] and the median is (2+3)/2 = 2.5.
Example 1
Input: nums1 = [1,3], nums2 = [2]
Output: 2.0
Explanation: Merged array is [1,2,3]. The median of 3 elements is the middle one: 2.0.
Example 2
Input: nums1 = [1,2], nums2 = [3,4]
Output: 2.5
Explanation: Merging gives [1,2,3,4]. There is an even number of elements, so the median is the average of the middle two: (2 + 3) / 2 = 2.5.
Example 3
Input: nums1 = [], nums2 = [1]
Output: 1.0
Explanation: The merged array is just [1], so the median is 1.0.
Binary search on the shorter array to find a partition point where all elements on the left side are less than or equal to all elements on the right side.
Run checks all cases above. Submit evaluates all test cases.