Skip to content

Commit ca7645b

Browse files
authored
Create 2226-maximum-candies-allocated-to-k-children.js
1 parent ab40986 commit ca7645b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} candies
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
const maximumCandies = function(candies, k) {
7+
let max = 1e12;
8+
let min = 0;
9+
while (min != max) {
10+
let mid = ~~((min + max + 1) / 2);
11+
let cnt = 0;
12+
for (let cand of candies) {
13+
cnt += ~~(cand / mid);
14+
}pnjj
15+
if (cnt < k) {
16+
max = mid - 1;
17+
} else {
18+
min = mid;
19+
}
20+
}
21+
return min;
22+
};

0 commit comments

Comments
 (0)