We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 51e2909 commit c9af93eCopy full SHA for c9af93e
3074.Apple-Redistribution-into-Boxes.java
@@ -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