这一题我以为会有什么动态规划之类的骚操作,但是最后还是耿直的思路写下来了 直接按照数组给定的顺序进行遍历,然后计算即可。 如果硬要有骚操作,我想。。。应该是给arrival排个序吧?
var averageWaitingTime = function (customers) {
let totalTime = 0
let currentTime = 0
for (let [arrival, time] of customers) {
// 当前时间
currentTime = Math.max(currentTime, arrival) + time
// 总等待时间
totalTime += currentTime - arrival
}
return totalTime / customers.length
};