1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-20 01:56:57 +02:00
LeetCode/rs/maximum-running-time-of-n-computers.rs
Matej Focko 2351dfd0ee
chore: unwrap one layer
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-12-12 14:36:00 +01:00

17 lines
452 B
Rust

impl Solution {
pub fn max_run_time(n: i32, mut batteries: Vec<i32>) -> i64 {
batteries.sort();
let mut total = batteries.iter().map(|x| *x as u64).sum::<u64>();
let mut k: u64 = 0;
while *batteries.last().unwrap() as u64 > total / (n as u64 - k) {
total -= *batteries.last().unwrap() as u64;
batteries.pop();
k += 1;
}
(total / (n as u64 - k)) as i64
}
}