Maximum Perimeter Triangle

  • + 0 comments

    Awesome rust solution ;)

    fn maximumPerimeterTriangle(mut sticks: Vec<i32>) -> Vec<i32> {
        sticks.sort();
        
        sticks
            .windows(3)
            .filter(|&window| window[0] + window[1] > window[2])
            .max_by_key(|&window| (window.iter().sum::<i32>(), window.iter().min().unwrap()))
            .unwrap_or(&[-1])
            .to_vec()
    }