https://programmers.co.kr/learn/courses/30/lessons/42578
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
Map<String, Integer> map = new HashMap<>();
for (String[] cloth : clothes) {
if (map.containsKey(cloth[1])) {
map.put(cloth[1], map.get(cloth[1]) + 1);
}
else {
map.put(cloth[1], 1);
}
}
for (String key : map.keySet()) {
answer *= (map.get(key) + 1);
}
return answer - 1;
}
}
의상의 종류, 개수를 갖는 HashMap
을 만들고 각 의상의 개수 + 1(그 옷을 안입은 경우)만큼 곱하고 1을 뺀다(모든 옷을 안입은 경우 1가지)