1165. Single-Row Keyboard

Обновлено: 2024-03-12
1 мин
[]

Содержание

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