[프로그래머스] LV2. 의상

인스·2025년 2월 10일

💡 내가 푼 풀이

✔️ HashMap

  • hashmap에 key = 종류, value = 개수 담기
  • value로 경우의 수 계산
import java.util.HashMap;

class Solution {
	public int solution(String[][] clothes) {
		HashMap<String, Integer> hm = new HashMap<>();

		for (int i = 0; i < clothes.length; i++) {
			int num = hm.getOrDefault(clothes[i][1], 0);
			hm.put(clothes[i][1], num + 1);
		}

		int answer = 1;
		for (String k : hm.keySet()) {
			answer *= (hm.get(k) + 1);
		}
		return answer - 1;
	}
}
profile
💻💡👻

0개의 댓글