Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 062bfc0

Browse files
K11E3Ryanglbme
andauthored
feat: add rust solution to lc problem: No.1701 (doocs#3241)
Co-authored-by: Libin YANG <contact@yanglibin.info>
1 parent 0620cfb commit 062bfc0

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

‎solution/1700-1799/1701.Average Waiting Time/README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ function averageWaitingTime(customers: number[][]): number {
161161
}
162162
```
163163

164+
#### Rust
165+
166+
```rust
167+
impl Solution {
168+
pub fn average_waiting_time(customers: Vec<Vec<i32>>) -> f64 {
169+
let mut tot = 0.0;
170+
let mut t = 0;
171+
172+
for e in customers.iter() {
173+
let a = e[0];
174+
let b = e[1];
175+
t = t.max(a) + b;
176+
tot += (t - a) as f64;
177+
}
178+
179+
tot / customers.len() as f64
180+
}
181+
}
182+
```
183+
164184
#### JavaScript
165185

166186
```js

‎solution/1700-1799/1701.Average Waiting Time/README_EN.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ function averageWaitingTime(customers: number[][]): number {
159159
}
160160
```
161161

162+
#### Rust
163+
164+
```rust
165+
impl Solution {
166+
pub fn average_waiting_time(customers: Vec<Vec<i32>>) -> f64 {
167+
let mut tot = 0.0;
168+
let mut t = 0;
169+
170+
for e in customers.iter() {
171+
let a = e[0];
172+
let b = e[1];
173+
t = t.max(a) + b;
174+
tot += (t - a) as f64;
175+
}
176+
177+
tot / customers.len() as f64
178+
}
179+
}
180+
```
181+
162182
#### JavaScript
163183

164184
```js
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
impl Solution {
2+
pub fn average_waiting_time(customers: Vec<Vec<i32>>) -> f64 {
3+
let mut tot = 0.0;
4+
let mut t = 0;
5+
6+
for e in customers.iter() {
7+
let a = e[0];
8+
let b = e[1];
9+
t = t.max(a) + b;
10+
tot += (t - a) as f64;
11+
}
12+
13+
tot / customers.len() as f64
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /