알고리즘/Lv2. 프로그래머스

[프로그래머스]의상 -JAVA

signal시노 2024. 8. 9. 17:36

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

코니는 변태인가보다..

경우의 수를 생각해보면 어떤 한 종류를 아예 안입는 경우까지 생각하면

종류의 아이템 개수 + 1 를 전부 곱해주고 싹 다 벗은 경우를 -1 해주면 될 것이다.

import java.util.*;
class Solution {
    public int solution(String[][] clothes) {
        int answer = 1;
        Map<String, Integer> map = new HashMap<>();
        for(int i = 0; i < clothes.length; i++) {
             map.put(clothes[i][1], map.getOrDefault(clothes[i][1], 0) + 1);
        }
           
        
        System.out.println(map);
        for(String key : map.keySet()) {
            answer *= (map.get(key) + 1);
        }
        return answer - 1;
    }
}