링크 : 프로그래머스 - 해시 > 위장
def solution(clothes):
answer = 1
dic = dict()
for value, key in clothes:
dic[key] = dic.get(key, 1) + 1 # 옷을 선택하지 않는 경우 포함
for value in dic.values():
answer *= value
return answer - 1
function solution(clothes) {
let answer = 1;
const dic = new Map();
for (let clothe of clothes){
dic.set(clothe[1], (dic.get(clothe[1]) || 1) + 1);
}
for (let [k, v] of dic){
answer *= v;
}
return answer - 1;
}
reduce사용한 코드도 실행해봤는데 map이 더 빠르다.