MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / average_waiting_time

Function average_waiting_time

1701-average-waiting-time.rs:1–14  ·  view source on GitHub ↗
(customers: Vec<Vec<i32>>)

Source from the content-addressed store, hash-verified

1pub fn average_waiting_time(customers: Vec<Vec<i32>>) -> f64 {
2 let mut time = 0f64;
3 let mut sum = 0f64;
4 for customer in &customers {
5 if customer[0] as f64 >= time {
6 sum += customer[1] as f64;
7 time = (customer[0] + customer[1]) as f64;
8 } else {
9 sum += time + (customer[1] - customer[0]) as f64;
10 time += customer[1] as f64;
11 }
12 }
13 sum as f64 / customers.len() as f64
14}
15
16fn main() {
17 println!("{:?}", average_waiting_time(vec![vec![1,2], vec![2,5], vec![4,3]]));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected