from collections import Counter
def solution(clothes):
num = [j for i, j in range(len(clothes))]
result = list(Counter(num).values())
i = 1
for r in result:
i = i * (r+1)
return i-1
풀이과정
- '의상의 종류'만 필요하기 때문에 따로 배열로 만든다.
- 각 종류의 개수를 세기 위해 Counter 클래스를 사용한다.
- (종류+1) * (종류+1) ... (종류+1) -1 을 해준다.
-1
은 아무것도 입지 않은 경우를 빼준 것이다.
2차 풀이
from collections import Counter
def solution(clothes):
kinds = []
for i in range(len(clothes)):
kinds.append(clothes[i][1])
result = 1
value = list(Counter(kinds).values())
for j in range(len(value)):
result *= value[j] + 1
return result-1