Skip to content

Commit 21ec308

Browse files
add 1974
1 parent 090803f commit 21ec308

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-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+
|1974|[Minimum Time to Type Word Using Special Typewriter](https://leetcode.com/problems/minimum-time-to-type-word-using-special-typewriter/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1974.java) ||Easy||
1112
|1968|[Array With Elements Not Equal to Average of Neighbors](https://leetcode.com/problems/array-with-elements-not-equal-to-average-of-neighbors/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1968.java) ||Medium||
1213
|1967|[Number of Strings That Appear as Substrings in Word](https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1967.java) ||Easy||
1314
|1961|[Check If String Is a Prefix of Array](https://leetcode.com/problems/check-if-string-is-a-prefix-of-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1961.java) ||Easy||
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1974 {
4+
public static class Solution1 {
5+
public int minTimeToType(String word) {
6+
int min = 0;
7+
char curr = 'a';
8+
for (int i = 0; i < word.length(); i++) {
9+
int diff = curr - word.charAt(i);
10+
curr = word.charAt(i);
11+
min += Math.min(diff + 26, Math.min(Math.abs(diff), 26 - diff));
12+
min++;
13+
}
14+
return min;
15+
}
16+
}
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1974;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _1974Test {
10+
private static _1974.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _1974.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(5, solution1.minTimeToType("abc"));
20+
}
21+
22+
@Test
23+
public void test2() {
24+
assertEquals(7, solution1.minTimeToType("bza"));
25+
}
26+
27+
@Test
28+
public void test3() {
29+
assertEquals(34, solution1.minTimeToType("zjpc"));
30+
}
31+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy