Skip to content

Commit a47487c

Browse files
authored
Create minimum-time-to-type-word-using-special-typewriter.cpp
1 parent 6a0bec2 commit a47487c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(n)
2+
// Space; O(1)
3+
4+
class Solution {
5+
public:
6+
int minTimeToType(string word) {
7+
int result = 0;
8+
char prev = 'a';
9+
for (const auto& c : word) {
10+
result += min(abs(c - prev), 26 - abs(c - prev)) + 1;
11+
prev = c;
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)