Skip to content

Commit 6d45f98

Browse files
authored
Create Put Boxes Into the Warehouse I.java
1 parent 70ca4fa commit 6d45f98

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int maxBoxesInWarehouse(int[] boxes, int[] warehouse) {
3+
Arrays.sort(boxes);
4+
for (int i = 1; i < warehouse.length; i++) {
5+
warehouse[i] = Math.min(warehouse[i - 1], warehouse[i]);
6+
}
7+
int count = 0;
8+
for (int i = warehouse.length - 1; i >= 0; i--) {
9+
if (count < boxes.length && boxes[count] <= warehouse[i]) {
10+
count++;
11+
}
12+
}
13+
return count;
14+
}
15+
}

0 commit comments

Comments
 (0)