Skip to content

Commit cc954d5

Browse files
solves slowest key
1 parent 32e53b5 commit cc954d5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404
| 1614 | [Maximum Nesting Depth of the Parentheses](https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses) | [![Java](assets/java.png)](src/MaximumNestingDepthOfTheParentheses.java) | |
405405
| 1619 | [Mean of Array After Removing Some Elements](https://leetcode.com/problems/mean-of-array-after-removing-some-elements) | [![Java](assets/java.png)](src/MeanOfArrayAfterRemovingSomeElements.java) | |
406406
| 1624 | [Largest Substring Between Two Equal Characters](https://leetcode.com/problems/largest-substring-between-two-equal-characters) | [![Java](assets/java.png)](src/LargestSubStringBetweenTwoEqualCharacters.java) | |
407-
| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | | |
407+
| 1629 | [Slowest Key](https://leetcode.com/problems/slowest-key) | [![Java](assets/java.png)](src/SlowestKey.java) | |
408408
| 1636 | [Sort Array by Increasing Frequency](https://leetcode.com/problems/sort-array-by-increasing-frequency) | | |
409409
| 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation) | | |
410410
| 1646 | [Get Maximum in Generated Array](https://leetcode.com/problems/get-maximum-in-generated-array) | | |

src/SlowestKey.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class SlowestKey {
2+
public char slowestKey(int[] releaseTimes, String keysPressed) {
3+
char slowestKey = keysPressed.charAt(0);
4+
int longestDuration = releaseTimes[0];
5+
for (int index = 1 ; index < keysPressed.length() ; index++) {
6+
if (releaseTimes[index] - releaseTimes[index - 1] > longestDuration) {
7+
longestDuration = releaseTimes[index] - releaseTimes[index - 1];
8+
slowestKey = keysPressed.charAt(index);
9+
} else if (releaseTimes[index] - releaseTimes[index - 1] == longestDuration) {
10+
slowestKey = (char) Math.max(slowestKey, keysPressed.charAt(index));
11+
}
12+
}
13+
return slowestKey;
14+
}
15+
}

0 commit comments

Comments
 (0)