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

Pixel Dophin·2023년 7월 20일
0

프로그래머스

목록 보기
24/55

의상

문제링크

풀이

map 자료구조를 활용헤 문제를 풀이 하였다.
경우의 수를 구한다고 생각해서 각 종류의 개수를 (없을 경우도 생각해 1을 추가한 후) 곱하고
다 없는 경우를 한가지 뺴주었다.

코드

import java.util.*;

class Solution {
    public int solution(String[][] clothes) {
        int answer = 1;
        
        Map<String, Integer> map = new HashMap<>();
        
        for (String[] cloth : clothes) {
            String clothName = cloth[0];
            String clothType = cloth[1];
            map.put(clothType, map.getOrDefault(clothType, 0) + 1);
        }
        
        for (int value : map.values()) {
            answer *= (value + 1);
        }
        answer--;
        
        return answer;
    }
}
profile
안녕 👋 성장하고픈 개발자 💻 입니다

1개의 댓글

comment-user-thumbnail
2023년 7월 20일

좋은 글 잘 읽었습니다, 감사합니다.

답글 달기

관련 채용 정보