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

Commita454a63

Browse files
add 3016
1 parent22de77d commita454a63

File tree

3 files changed

+56
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+56
-0
lines changed

‎paginated_contents/algorithms/4th_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
| 3024|[Type of Triangle](https://leetcode.com/problems/type-of-triangle/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3024.java)|| Easy|
7373
| 3028|[Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3028.java)|| Easy|
7474
| 3019|[Number of Changing Keys](https://leetcode.com/problems/number-of-changing-keys/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3019.java)|| Easy|
75+
| 3016|[Minimum Number of Pushes to Type Word II](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3016.java)|| Medium|
7576
| 3010|[Divide an Array Into Subarrays With Minimum Cost I](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3010.java)|| Easy|
7677
| 3014|[Minimum Number of Pushes to Type Word I](https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3014.java)|| Easy|
7778
| 3006|[Find Beautiful Indices in the Given Array I](https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3006.java)|| Medium|
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
importjava.util.PriorityQueue;
6+
7+
publicclass_3016 {
8+
publicstaticclassSolution1 {
9+
publicintminimumPushes(Stringword) {
10+
Map<Character,Integer>map =newHashMap<>();
11+
for (charc :word.toCharArray()) {
12+
map.put(c,map.getOrDefault(c,0) +1);
13+
}
14+
PriorityQueue<Map.Entry<Character,Integer>>maxHeap =newPriorityQueue<>((a,b) ->b.getValue() -a.getValue());
15+
for (Map.Entry<Character,Integer>entry :map.entrySet()) {
16+
maxHeap.offer(entry);
17+
}
18+
int[]possibleSets =newint[]{1,2,3,4};
19+
intdigitsLength =8;//a total of 8 digits that can be assigned
20+
Map<Character,Integer>assigned =newHashMap<>();
21+
for (intj =0;j <possibleSets.length && !maxHeap.isEmpty();j++) {
22+
for (inti =0;i <digitsLength && !maxHeap.isEmpty();i++) {
23+
Map.Entry<Character,Integer>curr =maxHeap.poll();
24+
assigned.put(curr.getKey(),possibleSets[j]);
25+
}
26+
}
27+
intans =0;
28+
for (Map.Entry<Character,Integer>entry :map.entrySet()) {
29+
ans +=entry.getValue() *assigned.get(entry.getKey());
30+
}
31+
returnans;
32+
}
33+
}
34+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
packagecom.fishercoder.fourththousand;
2+
3+
importcom.fishercoder.solutions.fourththousand._3016;
4+
importorg.junit.jupiter.api.BeforeEach;
5+
importorg.junit.jupiter.api.Test;
6+
7+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
8+
9+
publicclass_3016Test {
10+
privatestatic_3016.Solution1solution1;
11+
12+
@BeforeEach
13+
publicvoidsetup() {
14+
solution1 =new_3016.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(24,solution1.minimumPushes("aabbccddeeffgghhiiiiii"));
20+
}
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp