class Solution {
static int min = Integer.MAX_VALUE;
static int N;
public int solution(int a, int number) {
N=a;
calc(number,0,0);
return (min==Integer.MAX_VALUE) ? -1 : min;
}
public void calc(int number, int val, int count){
if(count>8) return;
if(val==number){
min=Math.min(min,count);
return;
}
int temp = 0;
for(int i=1; i<=8-count; i++){
temp=temp*10+N;
calc(number,val+temp,count+i);
calc(number,val-temp,count+i);
calc(number,val/temp,count+i);
calc(number,val*temp,count+i);
}
}
}
DFS긴 하지만 ,,,
이것도 넘 천재적이라 느낌;;;;;;;;;;;;;;;;; 하아 다시 풀어야지,.,
'NOTE > 프로그래머스' 카테고리의 다른 글
카펫 (0) | 2022.04.03 |
---|---|
등굣길 (0) | 2022.03.30 |
Level2 - 가장 큰 정사각형 찾기 (0) | 2022.03.16 |
Level2 - 올바른 괄호 (0) | 2022.03.14 |
Level2 - 다음 큰 숫자 (0) | 2022.03.14 |