Class Solution
java.lang.Object
g0001_0100.s0004_median_of_two_sorted_arrays.Solution
4 - Median of Two Sorted Arrays.<p>Hard</p>
<p>Given two sorted arrays <code>nums1</code> and <code>nums2</code> of size <code>m</code> and <code>n</code> respectively, return <strong>the median</strong> of the two sorted arrays.</p>
<p>The overall run time complexity should be <code>O(log (m+n))</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums1 = [1,3], nums2 = [2]</p>
<p><strong>Output:</strong> 2.00000</p>
<p><strong>Explanation:</strong> merged array = [1,2,3] and median is 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums1 = [1,2], nums2 = [3,4]</p>
<p><strong>Output:</strong> 2.50000</p>
<p><strong>Explanation:</strong> merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums1 = [0,0], nums2 = [0,0]</p>
<p><strong>Output:</strong> 0.00000</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> nums1 = [], nums2 = [1]</p>
<p><strong>Output:</strong> 1.00000</p>
<p><strong>Example 5:</strong></p>
<p><strong>Input:</strong> nums1 = [2], nums2 = []</p>
<p><strong>Output:</strong> 2.00000</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>nums1.length == m</code></li>
<li><code>nums2.length == n</code></li>
<li><code>0 <= m <= 1000</code></li>
<li><code>0 <= n <= 1000</code></li>
<li><code>1 <= m + n <= 2000</code></li>
<li><code>-10<sup>6</sup> <= nums1[i], nums2[i] <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findMedianSortedArrays
public double findMedianSortedArrays(int[] nums1, int[] nums2)
-