알고리즘 문제풀이📝 Hash(2)

KYU·2021년 7월 26일
0

프로그래머스 위장

https://programmers.co.kr/learn/courses/30/lessons/42578

🌙 방법

해당 정보를 hash안에 넣어준다
value값들에 1을 더하고 곱해준다(곱해줘야해서 1을 default로!)

function solution(clothes) {
    let hash={};
    let answer=1;
    
    for(let i=0; i<clothes.length; ++i){
        if(!hash[clothes[i][1]]){
            hash[clothes[i][1]]=1
        }else{
            hash[clothes[i][1]]+=1
        }
    }
    
   for(let i of Object.keys(hash)){
       answer *= (hash[i]+1)
   }  
   
   return answer-1
} 
profile
즐기기 위해 노력하는 개발자

0개의 댓글