1165. Single-Row Keyboard

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

On This Page

LeetCode problem 1165

class Solution:
    def calculateTime(self, keyboard: str, word: str) -> int:
        pos = {c: i for i, c in enumerate(keyboard)}
        res = i = 0
        for c in word:
            res += abs(pos[c] - i)
            i = pos[c]
        return res