You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let ratio = Math.floor(h/(piles.length));
let minspeed = Math.ceil(Math.min(...piles)/ratio);
let maxspeed = Math.ceil(Math.max(...piles)/ratio);
for(let i = minspeed; i<=maxspeed; i++){
let time = 0;
for(let pile of piles){
time += Math.ceil(pile/i);
}
if(time <= h){
return i;
}
}
Activity
sisterAn commentedon Sep 18, 2020
解答:二分查找
二分查找也称折半查找算法,它是一种简单易懂的快速查找算法。例如我随机写0-100之间的一个数字,让你猜我写的是什么?你每猜一次,我就会告诉你猜的大了还是小了,直到猜中为止。
该算法要求待查找的数组已排序,实现步骤如下:
对应于本题,二分查找查找的是珂珂吃香蕉的速度
K(不需要排序),我们已知的是:low) 是1high)复杂度分析:
n是香蕉堆的数量,m最大的香蕉堆的大小leetcode
Glittergalaxy commentedon Sep 18, 2020
marlboroKay commentedon Sep 18, 2020
xiaoyiyi123 commentedon Sep 18, 2020
第一次参与,加油
`var minEatingSpeed = function(piles, H) {
var left = 1, right = Math.max(...piles);
};`
zo11o commentedon Sep 22, 2020
超出时间限制,但是记录一下吧
LemonTency commentedon Apr 4, 2021
laiyingzeng commentedon Jun 18, 2021
Jet12138 commentedon Sep 12, 2022
var minEatingSpeed = function(piles, h) {
// 思路: 从最小速度,整数递增到最大速度,遍历出来一个刚好<=h时间把piles吃完的速度。
if(h === piles.length){
return Math.max(...piles);
}
};