위장 (프로그래머스)

Namlulu·2022년 1월 11일
0

알고리즘

목록 보기
10/28
function solution(clothes) {
    const store = {}
    for (let cloth of clothes) {
        if (cloth[1] in store) {
            store[cloth[1]].push(cloth[0])
        } else {
            store[cloth[1]] = [cloth[0]]
        }     
    }
    
    let answer = 1;
    
    for (let storeKey in store) {
        answer *= store[storeKey].length + 1
    }
    
    return answer - 1
}

=> 처음 잘못 생각했던 것이 옷을 안 입는 경우 때문에 안 입는 경우 + 나오게 되는 경우의 수로 계산해서 틀림
=> 옷을 안 입는 경우까지 모두 경우의 수로 구한 뒤, 아에 안 입는 케이스 1을 빼야 정답

profile
Better then yesterday

0개의 댓글