1165. Single-Row Keyboard
On This Page
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