map 자료구조를 활용헤 문제를 풀이 하였다.
경우의 수를 구한다고 생각해서 각 종류의 개수를 (없을 경우도 생각해 1을 추가한 후) 곱하고
다 없는 경우를 한가지 뺴주었다.
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
Map<String, Integer> map = new HashMap<>();
for (String[] cloth : clothes) {
String clothName = cloth[0];
String clothType = cloth[1];
map.put(clothType, map.getOrDefault(clothType, 0) + 1);
}
for (int value : map.values()) {
answer *= (value + 1);
}
answer--;
return answer;
}
}
좋은 글 잘 읽었습니다, 감사합니다.