summaryrefslogtreecommitdiff
path: root/median-of-two-sorted-arrays/src/main.rs
blob: a8557aadcd7bc02ff68966ccfce5c805b3e8b0bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    println!("Hello, world!");
    let tests = vec![
        (vec![1,3], vec![2], 2.0),
        (vec![1,2], vec![3,4], 2.5)
    ];
    for test in tests {
        println!("{:?}{:?} is {} should be {}", test.0, test.1,
                 Solution::find_median_sorted_arrays(test.0.clone(), test.1.clone()), test.2);
    }
}

struct Solution {}
impl Solution {
    pub fn find_median_sorted_arrays(nums1: Vec<i32>, nums2: Vec<i32>) -> f64 {
        let mut a = nums1.clone();
        a.append(&mut nums2.clone());
        a.sort();
        let median = a.get((a.len() / 2)-1..((a.len() + 1)/2)).unwrap();
        println!("{:?}", median);
        (median.iter().sum::<i32>() as f64) / (median.len() as f64)
    }
}