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

Commite906334

Browse files
add 1090
1 parenta8e89e0 commite906334

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ _If you like this project, please leave me a star._ ★
238238
|1103|[Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1103.java)||Easy|Math|
239239
|1100|[Find K-Length Substrings With No Repeated Characters](https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1100.java)||Medium|String, Sliding Window|
240240
|1099|[Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1099.java)|[:tv:](https://www.youtube.com/watch?v=2Uq7p7HE0TI)|Easy||
241+
|1090|[Largest Values From Labels](https://leetcode.com/problems/largest-values-from-labels/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1090.java)||Medium|HashTable, Greedy|
241242
|1089|[Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1089.java)||Easy||
242243
|1087|[Brace Expansion](https://leetcode.com/problems/brace-expansion/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1087.java)||Medium|Backtracking|
243244
|1086|[High Five](https://leetcode.com/problems/high-five/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1086.java)|[:tv:](https://www.youtube.com/watch?v=3iqC5J4l0Cc)|Easy||
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
importjava.util.HashMap;
5+
importjava.util.Map;
6+
7+
publicclass_1090 {
8+
publicstaticclassSolution1 {
9+
publicintlargestValsFromLabels(int[]values,int[]labels,intnumWanted,intuseLimit) {
10+
int[][]tuple =newint[values.length][2];
11+
for (inti =0;i <values.length;i++) {
12+
tuple[i][0] =values[i];
13+
tuple[i][1] =labels[i];
14+
}
15+
Arrays.sort(tuple, (a,b) ->b[0] -a[0]);
16+
Map<Integer,Integer>labelUsedCountMap =newHashMap<>();
17+
intsum =0;
18+
intnumbersUsed =0;
19+
for (inti =0;i <values.length;i++) {
20+
intval =tuple[i][0];
21+
intusedCount =labelUsedCountMap.getOrDefault(tuple[i][1],0);
22+
if (usedCount >=useLimit) {
23+
continue;
24+
}else {
25+
sum +=val;
26+
numbersUsed++;
27+
labelUsedCountMap.put(tuple[i][1],usedCount +1);
28+
}
29+
if (numbersUsed >=numWanted) {
30+
break;
31+
}
32+
}
33+
returnsum;
34+
}
35+
}
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1090;
4+
importcom.fishercoder.solutions._28;
5+
importorg.junit.Before;
6+
importorg.junit.Test;
7+
8+
importstaticjunit.framework.TestCase.assertEquals;
9+
10+
publicclass_1090Test {
11+
privatestatic_1090.Solution1solution1;
12+
13+
@Before
14+
publicvoidsetupForEachTest() {
15+
solution1 =new_1090.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
assertEquals(9,solution1.largestValsFromLabels(newint[]{5,4,3,2,1},newint[]{1,1,2,2,3},3,1));
21+
}
22+
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp