We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c7077aa commit 03eb68fCopy full SHA for 03eb68f
1 file changed
live9/test97/문제2/박희경.py
@@ -0,0 +1,29 @@
1
+def solution(name):
2
+ answer = 0
3
+
4
+ min_move = len(name) - 1 # 한칸씩 이동하는 경우
5
6
+ for i, char in enumerate(name):
7
+ # 위 아래로 움직일 때
8
+ answer += min(ord(char) - ord('A'), ord('Z') - ord(char) + 1)
9
10
+ # 연속된 A 끝나는 인덱스 찾기
11
+ next = i + 1
12
+ while next < len(name) and name[next] == 'A':
13
+ next += 1
14
15
+ """
16
+ len(name) - next : 'A' 구간이 끝난 후 남은 문자의 수
17
+ 1. 오른쪽으로 하나씩 가기 (최악의 경우)
18
+ 2. i까지 갔다가 → 되돌아와서(*2) → 남은 부분 끝까지 가기
19
+ 3. 뒷부분(next 이후)까지 갔다가 → 되돌아와서(*2) → 앞부분(i)까지 가기
20
21
+ min_move = min(min_move,
22
+ 2 * i + len(name) - next,
23
+ i + 2 * (len(name) - next)
24
+ )
25
26
+ answer += min_move
27
28
29
+ return answer
0 commit comments