Search

의상

알고리즘
해시
플랫폼
프로그래머스
JCF
HashMap
상태
해결
생성 일시
2023/12/18 11:52
최종 편집 일시
2023/12/19 07:40

문제 설명

해결과정

Solution.java

import java.util.*; class Solution { public int solution(String[][] clothes) { int answer = 0; HashMap<String, Integer> clothesCount = new HashMap<String, Integer>(); for(int i = 0; i < clothes.length; i++) { if(clothesCount.containsKey(clothes[i][1])) { clothesCount.put(clothes[i][1], clothesCount.get(clothes[i][1])+1); } else { clothesCount.put(clothes[i][1], 1); } } Collection<Integer> values = clothesCount.values(); int multi = 1; for (Integer value : values) { multi *= (value+1); } System.out.println(multi-1); answer = multi - 1; return answer; } }
Java
복사