문제 풀이 : HashMap을 이용하여, 매개변수로 받은 의상들을 비교를 했다.
1. HashMap에 있는 containsKey 메소드에 Key 값을 넘겨주면 해당 Key 값이 있으면 true, 없으면 false를 넘겨준다. 이 메소드를 통해 Key 값이 있다면 해당 Key의 Value 값을 +1 해준다
2. Key 값이 없다면 해당 Key 값과 Value 값을 put한다
import java.util.*; public class Disguise { public int solution(String[][] clothes) { HashMap<String, Integer> hm = new HashMap<String, Integer>(); int answer=1; for(int i =0 ;i<clothes.length;i++){ //3 if(hm.containsKey(clothes[i][1])){ hm.put(clothes[i][1],hm.get(clothes[i][1])+1); }else{ hm.put(clothes[i][1],1); } System.out.println("hm.get(clothes["+i+"][1]) : "+ hm.get(clothes[i][1])); } System.out.println("hm.size() :"+hm.size()); System.out.println("hm.value() :"+hm.values()); for(int a : hm.values()){ System.out.println("a :"+a); answer *= a+1; System.out.println("answer : "+answer); } answer--; System.out.println(answer+" = answer"); return answer; } }