알고리즘
프로그래머스-HashMap사용 : 위장 (getOfDefault)
제이G
2022. 7. 2. 12:48
import java.util.*;
import java.util.Map.*;
class Solution {
public int solution(String[][] clothes) {
Map<String, Integer> map = new HashMap<>();
for (int i=0; i<clothes.length; i++) {
map.put(clothes[i][1], map.getOrDefault(clothes[i][1], 1) + 1);
}
System.out.println(map);
Set<Entry<String, Integer>> set = map.entrySet();
Iterator it = set.iterator();
int result = 1;
while (it.hasNext()) {
Entry<String, Integer> entry = (Entry)it.next();
result = result * entry.getValue();
}
// System.out.println(result);
return result-1;
}
}