nums = [ord(list(name)[i]) for i in range(len(list(name)))]
for i in nums:
if 90 - i > i - 65:
answer = answer + (i - 65)
else:
answer = answer + (90 - i) + 1
move_nums = [min(ord(i) - ord("A"), ord("Z") - ord(i)+1) for i in name]
👩🏻🏫 풀이
def solution(name):
answer = 0
min_move = len(name) - 1
for i, char in enumerate(name):
answer += min(ord(char) - ord('A'), ord('Z') - ord(char) + 1)
next = i + 1
while next < len(name) and name[next] == 'A':
next += 1
min_move = min([min_move, 2 *i + len(name) - next, i + 2 * (len(name) -next)])
answer += min_move
return answer