728x90
다른 사람의 풀이
def solution(name):
change = [min(ord(i) - ord("A"), ord("Z")-ord(i)+1) for i in name]
print(change)
idx = 0
answer = 0
while True:
answer += change[idx]
change[idx] = 0
if sum(change) == 0:
return answer # until sum of change = 0
left, right = 1, 1
while change[idx - left] == 0:
left += 1
while change[idx + right] == 0:
right += 1
answer += left if left < right else right
idx += -left if left < right else right
728x90
'Algorithm' 카테고리의 다른 글
[프로그래머스] 소수 찾기 파이썬 (0) | 2021.03.10 |
---|---|
[Python] Heap (0) | 2021.03.10 |
[프로그래머스] 큰 수 만들기 (0) | 2021.03.04 |
[프로그래머스] 삼각 달팽이 (0) | 2021.03.04 |
[프로그래머스] 문자열 압축 파이썬 (1) | 2021.03.03 |
댓글