[Algorithm] 44 week(11.28 ~ 12.04) 1/3

Dev_min·2022년 11월 28일
0

algorithm

목록 보기
141/157

피로도

function solution(k, dungeons) {
    const listLength = dungeons.length;
    const visited = Array(listLength).fill(false);
    
    let maxCount = 0;
    
    function maxVisit(currentK, count){
        for(let i = 0; i < listLength; i++){
            if(!visited[i] && currentK >= dungeons[i][0]){
                visited[i] = true;
                maxVisit(currentK - dungeons[i][1], count + 1);
                visited[i] = false;  
            }
        }

        maxCount = Math.max(maxCount, count);
        return;
    };
    
    maxVisit(k, 0);
    
    
    return maxCount;
}
profile
TIL record

0개의 댓글