Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1e4d18

Browse files
authored
Create Minimized Maximum of Products Distributed to Any Store.java
1 parent5a3795b commitf1e4d18

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
classSolution {
2+
publicintminimizedMaximum(intn,int[]quantities) {
3+
intleft =0;
4+
intright =0;
5+
for (intquantity :quantities) {
6+
right =Math.max(right,quantity);
7+
}
8+
while (left <right) {
9+
intmid = (left +right) /2;
10+
if (isPossible(n,mid,quantities)) {
11+
right =mid;
12+
}else {
13+
left =mid +1;
14+
}
15+
}
16+
returnleft;
17+
}
18+
19+
privatebooleanisPossible(intn,intmin,int[]quantities) {
20+
intidx =0;
21+
intremaining =quantities[idx];
22+
for (inti =0;i <n;i++) {
23+
if (remaining <=min) {
24+
idx++;
25+
if (idx ==quantities.length) {
26+
returntrue;
27+
}else {
28+
remaining =quantities[idx];
29+
}
30+
}else {
31+
remaining -=min;
32+
}
33+
}
34+
returnfalse;
35+
}
36+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp