美文网首页
The Supermarket Queue 结账队列

The Supermarket Queue 结账队列

作者: Tiny_z | 来源:发表于2018-03-20 08:59 被阅读35次

给定一个数组(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)
}

相关文章

网友评论

      本文标题:The Supermarket Queue 结账队列

      本文链接:https://www.haomeiwen.com/subject/whhvqftx.html