public class NUM42860 {
public static void main(String[] args) {
String name = "JEROEN";
System.out.println(solution(name));
}
public static int solution(String name) {
int answer = 0;
int move = name.length() - 1;
for(int i = 0; i < name.length(); i++){
answer += Math.min(name.charAt(i) - 'A', 'Z' - name.charAt(i) + 1);
int next = i + 1;
while(next < name.length() && name.charAt(next) == 'A') {
next++;
}
if(next != i + 1) {
move = Math.min(move, i * 2 + name.length() - next);
move = Math.min(move, (name.length() - next) * 2 + i);
}
}
answer += move;
return answer;
}
}
*다른 분들의 코드를 참고하여 작성했습니다