We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6f2c69a commit bc45fe2Copy full SHA for bc45fe2
1 file changed
live9/test93/문제2/박희경.py
@@ -0,0 +1,22 @@
1
+def solution(name):
2
+ answer = 0
3
+
4
+ # 기본 최소 좌우 이동 횟수는 길이 - 1
5
+ min_move = len(name) - 1
6
7
+ for i, alpha in enumerate(name):
8
+ answer += min(ord(alpha) - ord('A'), ord('Z') - ord(alpha) + 1)
9
10
+ # 연속된 A의 끝나는 위치 찾기
11
+ next = i + 1
12
+ while next < len(name) and name[next] == 'A':
13
+ next += 1
14
15
+ min_move = min([
16
+ min_move, # 기존 오른쪽으로 끝까지 가는 경우
17
+ 2 * i + len(name) - next, # 처음부터 i까지 갔다가 뒤로 "돌아가기(*2)"
18
+ i + 2 * (len(name) - next) # A 지나서 끝까지 갔다가 "돌아오기(*2)"
19
+ ])
20
21
+ answer += min_move
22
+ return answer
0 commit comments