[programmers] 위장

KwonSC·2022년 5월 8일
0

programmers - Python

목록 보기
3/23
post-thumbnail

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


Code

def solution(clothes):
    dic = {}
    for a, b in clothes:
        if (b in dic):
            dic[b] += 1
        else:
            dic[b] = 1
    answer = 1
    for value in dic.values():
        answer *= value + 1
    return answer - 1

Solution

clothes의 종류에 맞게 딕셔너리에 개수를 카운팅 해주고 딕셔너리를 돌면서 카운팅값 + 1을 더해주고 마지막에 answer에서 1을 빼주고 리턴한다. 1은 아무것도 입지 않은 경우

0개의 댓글