Skip to content

Commit 31fab14

Browse files
authored
[20251116] PGM / LV2 / 조이스티 / 강신지
1 parent caceb3c commit 31fab14

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```java
2+
class Solution {
3+
public int solution(String name) {
4+
int answer = 0;
5+
6+
for (int i=0; i<name.length(); i++){
7+
int diff = name.charAt(i)-'A';
8+
answer += Math.min(diff, 26-diff);
9+
}
10+
11+
int move = name.length()-1;
12+
for (int i=0; i<name.length(); i++){
13+
int next = i+1;
14+
15+
while (next<name.length() && name.charAt(next)=='A'){
16+
next++;
17+
}
18+
19+
move = Math.min(move, i*2+(name.length()-next));
20+
move = Math.min(move, i+(name.length()-next)*2);
21+
}
22+
23+
return answer+move;
24+
}
25+
}
26+
```

0 commit comments

Comments
 (0)