[Programmers] 해시 - 위장 (JavaScript)

eunji lee·2022년 9월 23일
0

알고리즘

목록 보기
8/11
function solution(clothes) {
  var answer =1 ;
    const obj = {};
    clothes.map(clothe =>{
        if(obj[clothe[1]]) return obj[clothe[1]] += 1;
        return obj[clothe[1]] = 1;
    })
    const keys = Object.keys(obj);
    keys.forEach(key=>{
        answer *= obj[key]+1;
    })
     return answer -1 
}
  • 같은 종류의 의상은 겹칠 수 없음,
  • 최소 한개의 의상을 입어야함.
  • 선택이 안될 수 도 있음
profile
안녕하세요! 이은지 입니다.

0개의 댓글