출처: 프로그래머스 코딩 테스트 연습 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;
}
}
'알고리즘 > 프로그래머스' 카테고리의 다른 글
프로그래머스 뉴스 클러스터링 (0) | 2021.09.21 |
---|---|
프로그래머스 메뉴 리뉴얼 (0) | 2021.09.13 |
프로그래머스 순위 검색 (0) | 2021.09.09 |
프로그래머스 구명보트 (0) | 2021.09.07 |
프로그래머스 거리두기 확인하기 (0) | 2021.08.31 |