1974. 使用特殊打字机键入单词的最少时间
作者:互联网
class Solution:
def minTimeToType(self, word: str) -> int:
word = 'a' + word
ans = 0
for i in range(1, len(word)):
tmp = abs(ord(word[i]) - ord(word[i-1]))
if tmp > 13:
ans = ans + (26 - tmp) % 26
else:
ans = ans + tmp % 26
return ans + len(word) - 1
标签:tmp,26,word,1974,键入,len,打字机,ans,ord 来源: https://blog.csdn.net/FeNGQiHuALOVE/article/details/120754729