-
[프로그래머스 - 해시] 의상Coding Test 2023. 6. 24. 23:31728x90
import java.util.*; class Solution { public int solution(String[][] clothes) { Map<String, Integer> map = new HashMap<>(); // 옷의 종류별로 개수를 카운트 for (String[] cloth : clothes) { String type = cloth[1]; // getOrDefault(key, 기본값): key값이 있으면 기본값으로 설정 map.put(type, map.getOrDefault(type, 0) + 1); } int answer = 1; // 옷의 종류별로 선택할 수 있는 개수를 곱하여 조합 계산 for (int count : map.values()) { answer *= count + 1; } // -1 -> 아무 의상도 선택하지 않은 경우를 제외 return answer - 1; } }
728x90반응형'Coding Test' 카테고리의 다른 글
[프로그래머스] 체육복 (0) 2023.07.02 [프로그래머스 - 소수] 소수 찾기 (0) 2023.06.25 [프로그래머스 - DFS] 네트워크 (0) 2023.06.18 [프로그래머스 - 정렬] 가장 큰 수 (0) 2023.06.17 [프로그래머스 - Stack] 기능개발 (0) 2023.06.15