Skip to content

Commit 57743e2

Browse files
committed
feat: add solutions to lc problem: No.1701. Average Waiting Time
1 parent 3d82a5a commit 57743e2

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

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

+20-3
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,44 @@
5454
<li><code>arrival<sub>i </sub><= arrival<sub>i+1</sub></code></li>
5555
</ul>
5656

57-
5857
## 解法
5958

6059
<!-- 这里可写通用的实现逻辑 -->
6160

61+
记 totalWaitingTime 表示总等待时间,f 表示当次做菜完成时间。
62+
6263
<!-- tabs:start -->
6364

6465
### **Python3**
6566

6667
<!-- 这里可写当前语言的特殊实现逻辑 -->
6768

6869
```python
69-
70+
class Solution:
71+
def averageWaitingTime(self, customers: List[List[int]]) -> float:
72+
f = total_waiting_time = 0
73+
for arrival, time in customers:
74+
f = max(arrival, f) + time
75+
total_waiting_time += (f - arrival)
76+
return total_waiting_time / len(customers)
7077
```
7178

7279
### **Java**
7380

7481
<!-- 这里可写当前语言的特殊实现逻辑 -->
7582

7683
```java
77-
84+
class Solution {
85+
public double averageWaitingTime(int[][] customers) {
86+
int f = 0;
87+
double totalWaitingTime = 0;
88+
for (int[] customer : customers) {
89+
f = Math.max(f, customer[0]) + customer[1];
90+
totalWaitingTime += (f - customer[0]);
91+
}
92+
return totalWaitingTime / customers.length;
93+
}
94+
}
7895
```
7996

8097
### **...**

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

+18-3
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,36 @@ So the average waiting time = (2 + 6 + 4 + 1) / 4 = 3.25.
5050
<li><code>arrival<sub>i&nbsp;</sub>&lt;= arrival<sub>i+1</sub></code></li>
5151
</ul>
5252

53-
5453
## Solutions
5554

5655
<!-- tabs:start -->
5756

5857
### **Python3**
5958

6059
```python
61-
60+
class Solution:
61+
def averageWaitingTime(self, customers: List[List[int]]) -> float:
62+
f = total_waiting_time = 0
63+
for arrival, time in customers:
64+
f = max(arrival, f) + time
65+
total_waiting_time += (f - arrival)
66+
return total_waiting_time / len(customers)
6267
```
6368

6469
### **Java**
6570

6671
```java
67-
72+
class Solution {
73+
public double averageWaitingTime(int[][] customers) {
74+
int f = 0;
75+
double totalWaitingTime = 0;
76+
for (int[] customer : customers) {
77+
f = Math.max(f, customer[0]) + customer[1];
78+
totalWaitingTime += (f - customer[0]);
79+
}
80+
return totalWaitingTime / customers.length;
81+
}
82+
}
6883
```
6984

7085
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public double averageWaitingTime(int[][] customers) {
3+
int f = 0;
4+
double totalWaitingTime = 0;
5+
for (int[] customer : customers) {
6+
f = Math.max(f, customer[0]) + customer[1];
7+
totalWaitingTime += (f - customer[0]);
8+
}
9+
return totalWaitingTime / customers.length;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def averageWaitingTime(self, customers: List[List[int]]) -> float:
3+
f = total_waiting_time = 0
4+
for arrival, time in customers:
5+
f = max(arrival, f) + time
6+
total_waiting_time += (f - arrival)
7+
return total_waiting_time / len(customers)

0 commit comments

Comments
 (0)