프로그래머스 - 위장 Python

최대 1 분 소요

프로그래머스 - 위장

문제유형 : Hash 알고리즘, 파이썬

해결방법

파이썬의 dictionary를 이용해서 해쉬를 구현하는 단순한 문제이다.

def solution(clothes):
    answer = 1
    hashmap = {}
    for cloth in clothes:
        v, k = cloth
        if k not in hashmap:
            hashmap[k] = [v]
        elif k in hashmap:
            hashmap[k].append(v)
    
    keys = hashmap.keys()
    for key in keys:
        answer *= len(hashmap[key]) + 1

    return answer - 1

댓글남기기