Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func minEatingSpeed(piles []int, h int) int {
- l,r := 1, Max(piles)
- res := r
- for l<=r {
- k:=(l+r)/2
- hours:=0
- for _,p:= range piles {
- hours+= int(math.Ceil(float64(p)/float64(k)))
- }
- if hours <= h {
- res = min(res,k)
- r = k - 1
- }else {
- l = k + 1
- }
- }
- return res
- }
- func Max(arr []int) int {
- max := arr[0]
- for _, val := range(arr) {
- if max < val {
- max = val
- }
- }
- return max
- }
- func min(v,w int) int {
- if v > w{
- return w
- }
- return v
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement