Skip to content

Commit 5a02b7c

Browse files
authored
Create 1701-average-waiting-time.js
1 parent f59a988 commit 5a02b7c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

1701-average-waiting-time.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[][]} customers
3+
* @return {number}
4+
*/
5+
const averageWaitingTime = function(customers) {
6+
const n = customers.length
7+
let start = customers[0][0], end = start + customers[0][1]
8+
let sum = end - start
9+
for(let i = 1; i < n; i++) {
10+
end = end > customers[i][0] ? end + customers[i][1] : customers[i][0] + customers[i][1]
11+
sum += (end - customers[i][0])
12+
}
13+
14+
let res = sum / n
15+
16+
return res
17+
};

0 commit comments

Comments
 (0)