[프로그래머스] 의상 (Python)

yuuforest·2023년 10월 7일

해시

목록 보기
5/5
post-thumbnail

프로그래머스 문제 풀이 - 해시

📰 문제


문제 확인 🏃


💡 입출력 예제


[["yellow_hat", "headgear"], ["blue_sunglasses", "eyewear"], ["green_turban", "headgear"]]

>> 5

힌트.
1. yellow_hat
2. blue_sunglasses
3. green_turban
4. yellow_hat + blue_sunglasses
5. green_turban + blue_sunglasses
[["crow_mask", "face"], ["blue_sunglasses", "face"], ["smoky_makeup", "face"]]

>> 3

힌트.
1. crow_mask
2. blue_sunglasses
3. smoky_makeup

💬 풀이


🎵 첫번째 풀이

def solution(clothes):
    
    all_clothes = {}

    for _, key in clothes:
        all_clothes[key] = all_clothes.setdefault(key, 0) + 1

    answer = 1

    for value in all_clothes.values():
        answer *= (value+1)

    return answer-1


✒️ 생각


profile
🐥 Backend Developer 🐥

0개의 댓글