알고리즘/프로그래머스
프로그래머스 위장
anott
2021. 8. 18. 23:30
출처: 프로그래머스 코딩 테스트 연습 https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장
programmers.co.kr
생각
백준저지의 패션왕 신해빈(https://www.acmicpc.net/problem/9375)과 동일한 문제다.
코드
import java.util.HashMap;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
HashMap<String,Integer> cloth = new HashMap<>();
for(int i=0; i<clothes.length; i++) {
cloth.put(clothes[i][1], cloth.getOrDefault(clothes[i][1],0)+1);
}
for(int c: cloth.values()) {
answer = answer * (c+1);
}
answer--;
return answer;
}
}