diff --git a/solution/1700-1799/1701.Average Waiting Time/README.md b/solution/1700-1799/1701.Average Waiting Time/README.md index 2f9b35e9ec2e6..b627949ca92d5 100644 --- a/solution/1700-1799/1701.Average Waiting Time/README.md +++ b/solution/1700-1799/1701.Average Waiting Time/README.md @@ -161,6 +161,26 @@ function averageWaitingTime(customers: number[][]): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn average_waiting_time(customers: Vec>) -> f64 { + let mut tot = 0.0; + let mut t = 0; + + for e in customers.iter() { + let a = e[0]; + let b = e[1]; + t = t.max(a) + b; + tot += (t - a) as f64; + } + + tot / customers.len() as f64 + } +} +``` + #### JavaScript ```js diff --git a/solution/1700-1799/1701.Average Waiting Time/README_EN.md b/solution/1700-1799/1701.Average Waiting Time/README_EN.md index 32b4e2e0c8c5c..a2aa59bf13d9a 100644 --- a/solution/1700-1799/1701.Average Waiting Time/README_EN.md +++ b/solution/1700-1799/1701.Average Waiting Time/README_EN.md @@ -159,6 +159,26 @@ function averageWaitingTime(customers: number[][]): number { } ``` +#### Rust + +```rust +impl Solution { + pub fn average_waiting_time(customers: Vec>) -> f64 { + let mut tot = 0.0; + let mut t = 0; + + for e in customers.iter() { + let a = e[0]; + let b = e[1]; + t = t.max(a) + b; + tot += (t - a) as f64; + } + + tot / customers.len() as f64 + } +} +``` + #### JavaScript ```js diff --git a/solution/1700-1799/1701.Average Waiting Time/Solution.rs b/solution/1700-1799/1701.Average Waiting Time/Solution.rs new file mode 100644 index 0000000000000..50e748ce47295 --- /dev/null +++ b/solution/1700-1799/1701.Average Waiting Time/Solution.rs @@ -0,0 +1,15 @@ +impl Solution { + pub fn average_waiting_time(customers: Vec>) -> f64 { + let mut tot = 0.0; + let mut t = 0; + + for e in customers.iter() { + let a = e[0]; + let b = e[1]; + t = t.max(a) + b; + tot += (t - a) as f64; + } + + tot / customers.len() as f64 + } +}