https://school.programmers.co.kr/learn/courses/30/lessons/148653
문제
제한사항
코드
class Solution {
private static int answer = Integer.MAX_VALUE;
private static String str;
private static void DFS(int depth,int offset,int count) {
if(depth == -1) {
answer = Math.min(answer, count+offset);
return;
}
int num = str.charAt(depth)-'0'+offset;
DFS(depth-1,0,count+num);
DFS(depth-1,1,count+10-num);
}
public int solution(int storey) {
str = Integer.toString(storey);
DFS(str.length()-1,0,0);
return answer;
}
}
풀이