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