Skip to content

Commit 1c827db

Browse files
authored
Create Minimum Time to Type Word Using Special Typewriter.java
1 parent 259ec48 commit 1c827db

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int minTimeToType(String word) {
3+
int totalTime = 0;
4+
char currentChar = 'a';
5+
for (char c : word.toCharArray()) {
6+
int difference = Math.abs(c - currentChar);
7+
totalTime += 1 + Math.min(difference, 26 - difference);
8+
currentChar = c;
9+
}
10+
return totalTime;
11+
}
12+
}

0 commit comments

Comments
 (0)