Skip to content

Commit 8c3647b

Browse files
add 1629
1 parent 4651eaa commit 8c3647b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ _If you like this project, please leave me a star._ ★
99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
1111
|1630|[Arithmetic Subarrays](https://leetcode.com/problems/arithmetic-subarrays/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1630.java) ||Medium|Sort|
12+
|1629|[Slowest Key](https://leetcode.com/problems/slowest-key/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1629.java) ||Easy|Array|
1213
|1626|[Best Team With No Conflicts](https://leetcode.com/problems/best-team-with-no-conflicts/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1626.java) ||Medium|DP|
1314
|1625|[Lexicographically Smallest String After Applying Operations](https://leetcode.com/problems/lexicographically-smallest-string-after-applying-operations/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1625.java) ||Medium|BFS, DFS|
1415
|1624|[Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1624.java) ||Easy|String|
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
public class _1629 {
10+
public static class Solution1 {
11+
public char slowestKey(int[] releaseTimes, String keysPressed) {
12+
Map<Character, Integer> map = new HashMap<>();
13+
for (int i = 0; i < releaseTimes.length; i++) {
14+
char c = keysPressed.charAt(i);
15+
int duration;
16+
if (i == 0) {
17+
duration = releaseTimes[i];
18+
} else {
19+
duration = releaseTimes[i] - releaseTimes[i - 1];
20+
}
21+
if (!map.containsKey(c)) {
22+
map.put(c, duration);
23+
} else {
24+
int val = map.get(c);
25+
if (duration > val) {
26+
map.put(c, duration);
27+
}
28+
}
29+
}
30+
Map<Integer, List<Character>> map2 = new HashMap<>();
31+
for (char c : map.keySet()) {
32+
int duration = map.get(c);
33+
if (!map2.containsKey(duration)) {
34+
map2.put(duration, new ArrayList<>());
35+
}
36+
map2.get(duration).add(c);
37+
}
38+
int max = -1;
39+
for (int duration : map2.keySet()) {
40+
List<Character> chars = map2.get(duration);
41+
Collections.sort(chars);
42+
map2.put(duration, chars);
43+
max = Math.max(max, duration);
44+
}
45+
return map2.get(max).get(map2.get(max).size() - 1);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)