https://school.programmers.co.kr/learn/courses/30/lessons/42578
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
- 나의 코드
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
//의상종류 : 몇개
HashMap<String, Integer> kindCount = new HashMap<>();
for(String[] cloth : clothes) {
kindCount.put(cloth[1], kindCount.getOrDefault(cloth[1], 0)+1);
}
for(Integer cnt : kindCount.values()) {
//갯수+1 -> 안입는 경우
//예시) 헤드2 + 아이1 조합의 경우 => (2+1)*(1+1)-1 = 3*2-1 = 5
//헤드1, 헤드2, 헤드X => 3
//아이1, 아이X => 2
answer = answer * (cnt+1);
}
//아무것도 안입는 경우 -1
answer--;
return answer;
}
}
'공부 > 알고리즘' 카테고리의 다른 글
조이스틱 (0) | 2025.03.19 |
---|---|
백준 1753번 최단경로 (0) | 2025.03.18 |
숫자의 표현 (0) | 2025.01.04 |
JadenCase 문자열 만들기 (0) | 2025.01.04 |
부족한 금액 계산하기 (0) | 2025.01.04 |