Skip to content

Commit c9af93e

Browse files
committed
feat(leetcode): add No.3074
1 parent 51e2909 commit c9af93e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// https://leetcode.com/problems/apple-redistribution-into-boxes/description/
2+
// algorithms
3+
// Easy (62.8%)
4+
// Total Accepted: 29K
5+
// Total Submissions: 46.1K
6+
7+
8+
class Solution {
9+
10+
public int minimumBoxes(int[] apple, int[] capacity) {
11+
int appleSum = 0;
12+
13+
for (int n : apple) {
14+
appleSum += n;
15+
}
16+
17+
Arrays.sort(capacity);
18+
int capLen = capacity.length;
19+
20+
for (int i = capLen - 1; i >= 0; i--) {
21+
appleSum -= capacity[i];
22+
if (appleSum <= 0) {
23+
return capLen - i;
24+
}
25+
}
26+
27+
return -1;
28+
}
29+
30+
}

0 commit comments

Comments
 (0)