Algorithm/1일 1코테

[🥲 프로그래머스] 위장 - hash

대인보우 2021. 7. 23. 17:00
반응형

https://programmers.co.kr/learn/courses/30/lessons/42578

 

코딩테스트 연습 - 위장

 

programmers.co.kr

 

✅ 내가 쓴 풀이

def solution(clothes):
    clothes_hash = {}
    
    for clothe in clothes:
        if clothe[1] not in clothes_hash:
            clothes_hash[clothe[1]] = 1
        else:
            clothes_hash[clothe[1]] += 1

    answer = 1
    for clothe in clothes_hash.values():
        answer *= clothe+1 # 해당 카테고리를 아예 안입는 경우를 고려해서 +1
    return answer - 1 # 아무것도 안입는 것 제외

 

반응형