File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
004. Median of Two Sorted Arrays Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 4. Median of Two Sorted Arrays
2
+
3
+ Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
4
+
5
+ The overall run time complexity should be O(log (m+n)).
6
+
7
+
8
+ ### Example 1:
9
+
10
+ ** Input:** nums1 = [ 1,3] , nums2 = [ 2]
11
+ ** Output:** 2.00000
12
+ ** Explanation:** merged array = [ 1,2,3] and median is 2.
13
+
14
+
15
+ ### Example 2:
16
+
17
+ ** Input:** nums1 = [ 1,2] , nums2 = [ 3,4]
18
+ ** Output:** 2.50000
19
+ ** Explanation:** merged array = [ 1,2,3,4] and median is (2 + 3) / 2 = 2.5.
20
+
21
+
22
+ ### Constraints:
23
+
24
+ - nums1.length == m
25
+ - nums2.length == n
26
+ - 0 <= m <= 1000
27
+ - 0 <= n <= 1000
28
+ - 1 <= m + n <= 2000
29
+ - -10⁶ <= nums1[ i] , nums2[ i] <= 10⁶
30
+
31
+
You can’t perform that action at this time.
0 commit comments