아..지겹다. 개념이 없으니 삽질하는 시간은 많아지고..
package programmers5;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
public class Main {
public static void main(String[] args) {
String[][] clothes = new String[3][2];
clothes[0][0] = "yellow_hat";
clothes[0][1] = "headgear";
clothes[1][0] = "blue_sunglasses";
clothes[1][1] = "headgear";
clothes[2][0] = "green_turban";
clothes[2][1] = "headgear";
Solution sol = new Solution();
sol.solution(clothes);
System.out.println("여기");
}// void main
} // Main
class Solution {
public int solution(String[][] clothes) {
System.out.println("여기");
System.out.println(clothes.length);
HashMap<String, Integer> temp = new HashMap<>();
for (int i = 0; i < clothes.length; i++) {
// 만약 contain하면 숫자 증가.
if (temp.containsKey(clothes[i][1]))
temp.put(clothes[i][1],temp.get(clothes[i][1])+1);
// temp.computeIfPresent(clothes[i][1], arg1);
else
temp.put(clothes[i][1], 1);
}
Set set = temp.keySet();
Iterator itr = set.iterator();
int tempNum = 1;
while (itr.hasNext()) {
String key = (String) itr.next();
System.out.println("key는" + key);
System.out.println("value는" + temp.get(key));
tempNum = tempNum * (temp.get(key) + 1);
}
System.out.println("전체숫자는" + (tempNum-1));
// System.out.println(temp.values());
int answer = tempNum-1;
return answer;
}
}