def get_num_ops(s):
if s == s[::-1]:
return 0
else:
list_s = list(s)
alph = string.lowercase
len_s = len(s)
index = 0
num_ops = 0
while index < len_s:
if s[index] != s[(len_s - 1) - index]:
if s[(len_s - 1) - index] > s[index]:
list_s[(len_s - 1) - index] = list_s[index]
else:
list_s[index] = list_s[(len_s - 1) - index]
num_ops += abs(alph.find(s[(len_s - 1) - index]) - alph.find(s[index]))
index += 1
return num_ops / 2
评论列表
文章目录