🥈

# Koko Eating Bananas

Created
2022/01/21 01:26
문제 번호
875
카테고리
Array
Binary Search

### Code

 .css-15tnwsa{max-width:100%;width:100%;white-space:pre-wrap;word-break:break-word;padding:7px 9px;background-color:transparent;font-size:14px;line-height:20px;min-height:1em;}.css-15tnwsa:empty::after{content:" ";}제출 날짜 시간 메모리 2021/01/20 16 ms 6.6 MB
// 875. Koko Eating Bananas // // https://leetcode.com/problems/koko-eating-bananas/ // math package has been imported to call Ceil. // sort package has been imported to call Search for Binary Search. import ( "math" "sort" ) // minEatingSpeed function finds the minimum portion to eat bananas in h hours. // Parametric search has been used and this is done by Search function of sort package. func minEatingSpeed(piles []int, h int) int { max := 0 for _, p := range piles { if max < p { max = p } } k := sort.Search(max, func(x int) bool { if x == 0 { return len(piles) == 0 } sum := 0 for _, p := range piles { sum += int(math.Ceil(float64(p) / float64(x))) } return sum <= h }) return k }
Go