4. Median of Two Sorted Arrays Hard

@problem@discussion
#Array#Binary Search#Divide and Conquer



1/**
2 * [4] Median of Two Sorted Arrays
3 *
4 * Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
5 * The overall run time complexity should be O(log (m+n)).
6 *  
7 * Example 1:
8 * 
9 * Input: nums1 = [1,3], nums2 = [2]
10 * Output: 2.00000
11 * Explanation: merged array = [1,2,3] and median is 2.
12 * 
13 * Example 2:
14 * 
15 * Input: nums1 = [1,2], nums2 = [3,4]
16 * Output: 2.50000
17 * Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	nums1.length == m
23 * 	nums2.length == n
24 * 	0 <= m <= 1000
25 * 	0 <= n <= 1000
26 * 	1 <= m + n <= 2000
27 * 	-10^6 <= nums1[i], nums2[i] <= 10^6
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/median-of-two-sorted-arrays/
33// discuss: https://leetcode.com/problems/median-of-two-sorted-arrays/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn find_median_sorted_arrays(nums1: Vec<i32>, nums2: Vec<i32>) -> f64 {
39        0f64
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_4() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.