Skip to content

Commit d503fd8

Browse files
committed
solution: level2 - 피로도 문제 풀이
1 parent 8938fca commit d503fd8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

level-2/피로도.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - pereng11
4+
//완전 탐색, greedy O(N^2)
5+
function solution(k, dungeons) {
6+
let answer = 0;
7+
const visited = new Array(dungeons.length).fill(false);
8+
function dfs(k, total){
9+
answer = Math.max( answer, total );
10+
//모든 포인트를 출발점으로 전체 경우의 수 탐색
11+
//0번 인덱스를 출발로 삼은 greedy 탐색이 끝나면 1번 인덱스를 출발점으로 ~ 마지막 인덱스까지 반복
12+
for(let i = 0; i < dungeons.length; i++){
13+
if(!visited[i] && dungeons[i][0] <= k){
14+
visited[i] = true;
15+
dfs(k - dungeons[i][1], total+1);
16+
visited[i] = false;
17+
}
18+
}
19+
}
20+
dfs(k, 0);
21+
return answer;
22+
}

0 commit comments

Comments
 (0)