본문 바로가기
알고리즘 공부/프로그래머스

프로그래머스 코딩테스트 고득점 Kit 해시 위장 문제 풀이

by 인생즐겜러 2023. 2. 3.
728x90
반응형

 

 

 

import java.util.*;

class Solution {
    public int solution(String[][] clothes) {
        HashMap<String, Integer> clo = new HashMap<>();
        int[] num = new int[30];
        int answer = 0;
        
        for(int i = 0 ; i < clothes.length ; i++){
            clo.put(clothes[i][1], clo.getOrDefault(clothes[i][1], 0) + 1);
        }
        
        int a = 0;
        for(String keys : clo.keySet()){
                num[a] = clo.get(keys) + 1;
                a++;
        }
        
        for(int i = 0 ; i < a ; i++){
            if(i==0){
                answer = num[i];
            }else{
                answer *= num[i];
            }
        }
        
        return (answer-1);
    }
}
728x90
반응형

댓글