알고리즘[Python]/프로그래머스
[ Lv 2 ] 위장
병훈1234
2021. 6. 26. 01:22
- itertools의 combinations 썼다가 시간초과가 났는데 간단하게 풀 수 있었음.
- 그냥 옷을 입거나 입지 않는 경우가 있으므로 옷의 종류별로 모든 경우를 곱해준다.
- 마지막에 옷을 입지 않는 경우를 -1 해주면 된다.
def solution(clothes):
answer = 1
clo = {}
for cloth, types in clothes:
if clo.get(types) == None:
clo[types] = 0
clo[types] += 1
p = clo.values()
for i in p:
answer *= (i+1)
return answer - 1
출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges