이번 문제는 그냥 코드 공유만 하려고 한다.
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
Map<String, Integer> counts = new HashMap<>();
for (String[] clothe : clothes) {
String type = ;
counts.put(clothe[1], counts.getOrDefault(clothe[1], 0) + 1);
}
int answer = 1;
for (Integer count : counts.values()) {
answer *= count + 1;
}
return answer - 1;
}
}
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
Map<String, Integer> counts = new HashMap<>();
for (String[] clothe : clothes) {
counts.put(clothe[1], counts.getOrDefault(clothe[1], 0) + 1);
}
return counts.values().stream().reduce(1, (a, b) -> a * (b + 1)) - 1;
}
}
import java.util.*;
import java.util.stream.*;
class Solution {
public int solution(String[][] clothes) {
return Arrays.stream(clothes)
.collect(Collectors.groupingBy(clothe -> clothe[1], Collectors.counting()))
.values().stream().reduce(1L, (a, b) -> a * (b + 1)).intValue() - 1;
}
}