[프로그래머스 | 파이썬] 위장

devheyrin·2022년 7월 1일
0

codingtest

목록 보기
64/65

문제 링크

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

코드

def solution(clothes):
    diction = {}
    for name, ctype in clothes:
        if ctype in diction:
            diction[ctype].append(name)
        else:
            diction[ctype] = [name]
            
    ans = 1
    for key in diction:
        ans *= len(diction[key]) + 1
    
    return ans - 1

풀이 설명

백준에서 한번 틀렸던 문제인데 또 틀렸다..
접근방식이 아예 다르다!!
[모자1, 모자2, 모자3], [상의1, 상의2, 상의3, 상의4]
이렇게 있다면 종류별로 입지 않는 경우를 1 추가해준다음 각 종류별 개수를 구한다.
여기에 '안입음, 안입음' 경우가 포함되어있으므로 1을 빼주면 끝!

profile
개발자 헤이린

0개의 댓글