import java.util.HashMap;
public class Camouflage {
public int solution(String[][] clothes) {
int answer = 1;
HashMap<String, Integer> map = new HashMap<>();
for (String[] ele : clothes) {
if (map.containsKey(ele[1])) {
map.replace(ele[1], map.get(ele[1]) + 1);
} else {
map.put(ele[1], 1);
}
}
for (String ele : map.keySet()) {
answer *= (map.get(ele) + 1);
}
return answer - 1;
}
public static void main(String[] args) {
Camouflage s = new Camouflage();
String[][] clothes1 = { { "yellow_hat", "headgear" }, { "blue_sunglasses", "eyewear" },
{ "green_turban", "headgear" } };
String[][] clothes2 = { { "crow_mask", "face" }, { "blue_sunglasses", "face" }, { "smoky_makeup", "face" } };
String[][] clothes3 = { { "yellow_hat", "headgear" }, { "blue_sunglasses", "eyewear" },
{ "green_turban", "headgear" }, { "neck tie", "neck" } };
System.out.println(s.solution(clothes1));
System.out.println(s.solution(clothes2));
System.out.println(s.solution(clothes3));
}
}
Map.containsKey(Object key) : 키를 포함하고 있는지 구하는 함수
Map.replace(Object key, Object value) : 해당 key의 value를 해당 value로 변경