shining park 2025. 1. 4. 18:12

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

- 나의 코드

import java.util.*;

class Solution {
    public int solution(String[][] clothes) {
        int answer = 1;
        
        //의상종류 : 몇개
        HashMap<String, Integer> kindCount = new HashMap<>();
        for(String[] cloth : clothes) {
            kindCount.put(cloth[1], kindCount.getOrDefault(cloth[1], 0)+1);
        }

        for(Integer cnt : kindCount.values()) {
            //갯수+1 -> 안입는 경우
            //예시) 헤드2 + 아이1 조합의 경우 => (2+1)*(1+1)-1 = 3*2-1 = 5
            //헤드1, 헤드2, 헤드X => 3
            //아이1, 아이X => 2
            answer = answer * (cnt+1);
        }
        
        //아무것도 안입는 경우 -1
        answer--;
        
        return answer;
    }
}