던전 array 순서대로 처음부터 탐색 -> 점점 깊게 들어가는 방식
function solution(k, dungeons) {
let max = 0;
let visit = new Array(dungeons.length).fill(false);
function dfs(cur,tired,depth){
visit[cur] = true;
tired-=dungeons[cur][1];
for(let i = 0; i < dungeons.length; i++){
if(!visit[i]&&tired>=dungeons[i][0])dfs(i,tired,depth+1);
}
max = Math.max(max,depth);
visit[cur] = false;
}
for(let i = 0 ; i < dungeons.length; i++){
if(dungeons[i][0]<=k)dfs(i,k,1);
}
return max;
}
'코테 준비 > [JS] 프로그래머스' 카테고리의 다른 글
프로그래머스 Lv.2 : 소수 찾기 - 완전 탐색 (0) | 2024.08.05 |
---|---|
프로그래머스 Lv.2 : 가장 큰 수 - 정렬 (0) | 2024.08.05 |
프로그래머스 Lv.2 : 타겟 넘버 - DFS (0) | 2024.08.05 |
프로그래머스 0단계: 정답률 25% - 옹알이(1) (0) | 2024.08.05 |
프로그래머스 0단계: 정답률 44% - 평행 (0) | 2024.08.05 |