1974. Minimum Time to Type Word Using Special Typewriter

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1974

class Solution:
    def minTimeToType(self, word: str) -> int:
        res = prev = 0
        for c in word:
            curr = ord(c) - ord('a')
            t = abs(prev - curr)
            t = min(t, 26 - t)
            res += t + 1
            prev = curr
        return res