mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
go: add «1701. Average Waiting Time»
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
a0c53fcdeb
commit
8198249ac5
1 changed files with 15 additions and 0 deletions
15
go/average-waiting-time.go
Normal file
15
go/average-waiting-time.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package main
|
||||
|
||||
func averageWaitingTime(customers [][]int) float64 {
|
||||
waitingTime := 0
|
||||
|
||||
idleAt := 0
|
||||
for _, customer := range customers {
|
||||
arrives, length := customer[0], customer[1]
|
||||
|
||||
idleAt = max(idleAt, arrives) + length
|
||||
waitingTime += idleAt - arrives
|
||||
}
|
||||
|
||||
return float64(waitingTime) / float64(len(customers))
|
||||
}
|
Loading…
Reference in a new issue