Algorithm/프로그래머스
해시 - 의상 (프로그래머스)
jun_code
2025. 1. 15. 22:21
<문제>
https://school.programmers.co.kr/learn/courses/30/lessons/42578?language=python3
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
<코드>
def solution(clothes):
dict_cloth = {}
answer = 1
for cloth, types in clothes:
if types not in dict_cloth.keys():
dict_cloth[types] = [cloth]
else:
dict_cloth[types].append(cloth)
for i in dict_cloth.keys():
answer *= (len(dict_cloth[i])+1)
return answer -1
<풀이>
- dict로 경우의 수 계산
- 각 종류별로 1개씩 선택할 수 있으므로 n * m * l ...
- 단, 최소 한가지는 선택해야하므로 각 종류별로 하나도 선택하지 않는 경우를 빼줘야 하므로 마지막 -1