💻 문제 풀이 : Python
⭐ 내 풀이
def solution(clothes):
hash_map = {}
for clothe, type in clothes:
#옷 종류의 가짓 수 저장, 이전에 값이 있었으면 기존 값에 +1
hash_map[type] = hash_map.get(type, 0) + 1
print(hash_map)
answer = 1
for type in hash_map:
#모든 옷 종유에 대해서 안 입는 경우도 있기 때문에 +1을 해줌
answer *= (hash_map[type] + 1)
print(hash_map)
return answer - 1 #아무것도 입지 않은 경우 1를 제외 시켜줌
📌 memo
hash_map.get(type, 0)
# None인 경우 0을 리턴한다!
def solution(clothes):
answer = 0
dic = {}
for cloth in clothes:
if dic.get(cloth[1]) == None:
dic[cloth[1]] = [cloth[0]]
else:
dic[cloth[1]].append(cloth[0])
# print(dic, len(dic))