clothes | return |
---|---|
[["yellowhat", "headgear"], ["bluesunglasses", "eyewear"], ["green_turban", "headgear"]] | 5 |
[["crowmask", "face"], ["bluesunglasses", "face"], ["smoky_makeup", "face"]] | 3 |
딕셔너리 이용(해시 테이블)
여집합.
하루에 최소 한개는 입는다면, 각 종류에 대해 안 입는 경우까지 포함해서 곱한 다음 모두 안입는 한 경우를 빼주면 된다.
def solution(clothes):
table = dict()
for a, b in clothes:
if b in table:
table[b] += 1
else:
table[b] = 1
ans = 1
for k, v in table.items():
ans *= (v+1)
return ans-1