728x90
반응형
Java
import java.util.*;
class Solution {
public int solution(String[][] clothes) {
int answer = 1;
Map<String, Integer> map = new HashMap<>();//의상종류, 의상개수
for(int i = 0; i < clothes.length; i++){
map.put(clothes[i][1], map.getOrDefault(clothes[i][1], 0) + 1);
}
for(String key : map.keySet()){
answer *= (map.get(key) + 1);
}
return answer - 1;
}
}
Python
def solution(clothes):
answer = 1
clothesMap = dict()
for i in range(len(clothes)):
clothesMap[clothes[i][1]] = clothesMap[clothes[i][1]] + 1 if clothes[i][1] in clothesMap else 1
for key in clothesMap.keys():
answer *= (clothesMap[key] + 1)
return answer - 1
728x90
반응형