Skip to content

Commit 11eec63

Browse files
authored
Update 2226-maximum-candies-allocated-to-k-children.js
1 parent ca7645b commit 11eec63

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

2226-maximum-candies-allocated-to-k-children.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
* @return {number}
55
*/
66
const maximumCandies = function(candies, k) {
7-
let max = 1e12;
7+
let max = candies.reduce((ac, e) => ac + e, 0);
88
let min = 0;
9-
while (min != max) {
10-
let mid = ~~((min + max + 1) / 2);
9+
while (min < max) {
10+
let mid = max - Math.floor((max - min) / 2);
1111
let cnt = 0;
1212
for (let cand of candies) {
1313
cnt += ~~(cand / mid);
14-
}pnjj
14+
}
1515
if (cnt < k) {
1616
max = mid - 1;
1717
} else {

0 commit comments

Comments
 (0)