给定一个数组(customers),里面每个元素表示每个顾客结账所需时间
然后给定一个整数(n) ,表示总共有多少个柜台可以结账
不允许插队
例如
customers:[10,2,3,3],
n:2
返回 10
其实就是把当前的顾客给到最空闲的那个柜台去结账
function queueTime(customers, n) {
let temp = Array(n).fill(0)
customers.map(item => {
let idx = temp.indexOf(Math.min(...temp))
temp[idx] += item
})
return Math.max(...temp)
}
网友评论