LeetCode-1701 平均等待时间
题目链接:1701. 平均等待时间 - 力扣(LeetCode)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| class Solution(object): def averageWaitingTime(self, customers): """ :type customers: List[List[int]] :rtype: float """ total=0 time_now=0 n=len(customers) wait=[] for i in range(n): wait.append(0) if n==0: return 0 time_now=customers[0][0] for i in range(n): if i==0: time_now=time_now+customers[i][1] wait[0]=customers[0][1] elif time_now>=customers[i][0]: time_now=time_now+customers[i][1] wait[i]=time_now-customers[i][0] else: time_now=customers[i][0]+customers[i][1] wait[i]=customers[i][1] for i in range(n): total=total+wait[i] return float(total)/n
|