Re: [闲聊] 每日leetcode

楼主: sustainer123 (caster)   2024-07-09 10:45:35
※ 引述《DJYOMIYAHINA (通通打死)》之铭言:
: 剩肥肥没钱去餐厅吃饭了
: 乖乖出门坐一个小时车去当帕鲁
: :(
: def averageWaitingTime(self, customers: List[List[int]]) -> float:
: finish_t = 0
: waiting_sum = 0
: for c in customers:
: finish_t = max(finish_t+c[1], c[0]+c[1])
: waiting_sum += (finish_t-c[0])
: return waiting_sum/len(customers)
思路:
照题目叙述模拟
Python Code:
class Solution:
def averageWaitingTime(self, customers: List[List[int]]) -> float:
finishes = 0
waiting_time = 0
for i in range(len(customers)):
if customers[i][0] > finishes:
waiting_time += customers[i][1]
finishes = customers[i][1] + customers[i][0]
else:
finishes += customers[i][1]
waiting_time += finishes - customers[i][0]
return waiting_time/len(customers)
写得有点丑 姆咪
不过身体终于好点了
脑袋没那么晕
作者: wwndbk (黑人问号)   2024-07-09 10:49:00
别卷了
作者: oin1104 (是oin的说)   2024-07-09 10:58:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com