We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b05a782 commit 472c6a5Copy full SHA for 472c6a5
907-koko-eating-bananas/koko-eating-bananas.cpp
@@ -0,0 +1,33 @@
1
+class Solution {
2
+public:
3
+ int maxele(vector<int>& piles, int n){
4
+ int maxi = INT_MIN;
5
+ for(int i = 0; i < n; i++){
6
+ maxi = max(maxi, piles[i]);
7
+ }
8
+ return maxi;
9
10
+ long long func(vector<int>& piles, int k, int n){
11
+ long long totalH = 0;
12
13
+ totalH += ceil((double)(piles[i])/ (double)(k));
14
15
+ return totalH;
16
17
+ int minEatingSpeed(vector<int>& piles, int h) {
18
+ int n = piles.size();
19
+ int low = 1;
20
+ int high = maxele(piles, n);
21
+ int ans = 1;
22
+ while(low <= high){
23
+ int mid = low + (high - low) / 2;
24
+ long long totalH = func(piles, mid, n);
25
+ if(totalH <= h){
26
+ ans = mid;
27
+ high = mid - 1;
28
29
+ else low = mid + 1;
30
31
+ return ans;
32
33
+};
0 commit comments