- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1701.java
23 lines (22 loc) · 836 Bytes
/
_1701.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
packagecom.fishercoder.solutions.secondthousand;
publicclass_1701 {
publicstaticclassSolution1 {
/*
* A simple one-pass, just simulate what the problem describes.
*/
publicdoubleaverageWaitingTime(int[][] customers) {
longtotalWaitTime = customers[0][1];
intchefFinishTime = customers[0][0] + customers[0][1];
for (inti = 1; i < customers.length; i++) {
intarrival = customers[i][0];
intprep = customers[i][1];
if (chefFinishTime < arrival) {
chefFinishTime = arrival;
}
chefFinishTime += prep;
totalWaitTime += chefFinishTime - arrival;
}
return (double) totalWaitTime / customers.length;
}
}
}