알고리즘 스터디
[프로그래머스] 해시 3. 위장
cme10575
2021. 4. 3. 22:19
문제
풀이
1. 종류별로 몇 개의 의상이 있는지 딕셔너리에 저장
ex { 'headgear: 1', 'eyeware': 2 }
2. 각 종류에 착용하지 않는 경우의 수 1을 더해 서로 곱함
3. 모두 착용하지 않는 경우의 수인 1을 뺌
def solution(clothes):
clothes_count = {}
for c in clothes:
if not c[1] in clothes_count:
clothes_count[c[1]] = 0
clothes_count[c[1]] += 1
answer = 0
for k, v in clothes_count.items():
if answer == 0:
answer = v + 1
else:
answer *= (v + 1)
return answer - 1
지난 주에 킥스타트 코테를 보고 와서 그런지 아주 선녀같은 난도였다.
문법
딕셔너리 순회
for key, value in dictionary.items():