Clicky

Leetcode 1701 "Avarage Waiting Time"

January 1, 0001

1701. Average Waiting Time

Result

Runtime: 3 ms, faster than 52.34% of Java online submissions for Average Waiting Time.

Memory Usage: 90.1 MB, less than 32.94% of Java online submissions for Average Waiting Time.

class Solution {
    public double averageWaitingTime(int[][] customers) {
        int finishedAtTime = 1;
        double total = 0;
        for(int i=0; i<customers.length; i++) {
            finishedAtTime = Math.max(finishedAtTime, customers[i][0]) + customers[i][1];
            total = total + (finishedAtTime - customers[i][0]);
        }
        return total/customers.length;
    }
}