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

Commit01d1acb

Browse files
add 1710
1 parent1503ff5 commit01d1acb

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+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_1710 {
6+
publicstaticclassSolution1 {
7+
publicintmaximumUnits(int[][]boxTypes,inttruckSize) {
8+
Arrays.sort(boxTypes, (a,b) ->b[1] -a[1]);
9+
inttotalUnits =0;
10+
intloadedBoxes =0;
11+
for (inti =0;i <boxTypes.length;i++) {
12+
intnumber =boxTypes[i][0];
13+
while (loadedBoxes <truckSize &&number >0) {
14+
totalUnits +=boxTypes[i][1];
15+
number--;
16+
loadedBoxes++;
17+
}
18+
}
19+
returntotalUnits;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp