Skip to content

Commit 10ae864

Browse files
authored
Create 1760. Minimum Limit of Balls in a Bag (#654)
2 parents 0defde5 + 62a0ea3 commit 10ae864

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

1760. Minimum Limit of Balls in a Bag

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int minimumSize(vector<int>& nums, int maxOps) {
4+
int low = 1, high = *max_element(nums.begin(), nums.end());
5+
while (low < high) {
6+
int mid = low + (high - low) / 2;
7+
int ops = 0;
8+
for (int n : nums) if ((ops += (n - 1) / mid) > maxOps) break;
9+
ops <= maxOps ? high = mid : low = mid + 1;
10+
}
11+
return high;
12+
}
13+
};

0 commit comments

Comments
 (0)