알고리즘

[프로그래머스] 의상

hminor 2023. 6. 25. 17:27
# 한참 고민하다가 다른 분의 힌트를 받고 해답을 알게 됨.
# 힌트는 각 섹션별로 착용하지 않는걸 생각한다면 편할 것 같다.
# 예를 들어 아래와 같이 종류가 세가지가 있고 종류마다 2가지의 아이템인 (red, blue)이 있다고 했을 경우
# ["headgear", "eyewear", "underwear"]
# 	red, blue, no 이렇게 3가지의 경우로 생각한다면 
#   각 아이템 별로 개수를 곱한 다음 모든 아이템을 안입는(no) 경우인 
#  headgear-no, eyewear-no, underwear-no 인 경우를 하나 뺀 걸 return 하는 방식.

from math import prod

def solution(clothes):
    dic = {}
    for i in clothes:
        try: dic[i[1]] += 1
        except: dic[i[1]] = 1
        
    li = [i+1 for i in list(dic.values())]
    return prod(li)-1