Skip to content

Commit 01d1acb

Browse files
add 1710
1 parent 1503ff5 commit 01d1acb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1710|[Maximum Units on a Truck](https://leetcode.com/problems/largest-subarray-length-k/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1708.java) ||Easy|Array, Greedy|
1112
|1708|[Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1708.java) ||Easy|Array, Greedy|
1213
|1704|[Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1704.java) ||Easy|String|
1314
|1700|[Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1700.java) ||Easy|Array|
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _1710 {
6+
public static class Solution1 {
7+
public int maximumUnits(int[][] boxTypes, int truckSize) {
8+
Arrays.sort(boxTypes, (a, b) -> b[1] - a[1]);
9+
int totalUnits = 0;
10+
int loadedBoxes = 0;
11+
for (int i = 0; i < boxTypes.length; i++) {
12+
int number = boxTypes[i][0];
13+
while (loadedBoxes < truckSize && number > 0) {
14+
totalUnits += boxTypes[i][1];
15+
number--;
16+
loadedBoxes++;
17+
}
18+
}
19+
return totalUnits;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)