Re: [閒聊] 每日leetcode已回收

看板Marginalman作者 (smart0eddie)時間1年前 (2024/07/09 11:38), 編輯推噓0(001)
留言1則, 1人參與, 1年前最新討論串466/1554 (看更多)
2024-07-09 1701. Average Waiting Time There is a restaurant with a single chef. You are given an array customers, where customers[i] = [arrivali, timei]: arrivali is the arrival time of the ith customer. The arrival times are sorted in non-decreasing order. timei is the time needed to prepare the order of the ith customer. When a customer arrives, he gives the chef his order, and the chef starts preparing it once he is idle. The customer waits till the chef finishes preparing his order. The chef does not prepare food for more than one customer at a time. The chef prepares food for customers in the order they were given in the input. Return the average waiting time of all customers. Solutions within 10-5 from the actual answer are considered accepted. 就照著題目敘述刻一個程式跑模擬 這題為什麼會是med啊 class Solution { public: double averageWaitingTime(vector<vector<int>>& customers) { double waitTime = customers[0][1]; int end = customers[0][0] + customers[0][1]; for (int c = 1; c < customers.size(); c++) { waitTime += customers[c][1]; if (end > customers[c][0]) { waitTime += end - customers[c][0]; end = end + customers[c][1]; } else { end = customers[c][0] + customers[c][1]; } } return waitTime / customers.size(); } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 73.173.211.221 (美國) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1720496295.A.36F.html

07/09 11:46, 1年前 , 1F
技術大神
07/09 11:46, 1F
文章代碼(AID): #1cZB2dDl (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cZB2dDl (Marginalman)