https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장
programmers.co.kr
풀이 유형 : 해시 Hash
1차 시도
def solution(clothes):
dic = {}
answer = 1
for cloth in clothes:
dic[cloth[1]] = dic.get(cloth[1], []) + [cloth[0]]
for i in dic:
answer *= len(dic[i])+1
return answer-1
💡 최종 로직
0. 주어진 clothes를 사용하여 dictionary를 만든다
1. dic를 순회하며 (각 value의 갯수 +1)을 answer에 곱한다
+1을 하는 이유 : 각 의상 타입에 "안입음"이라는 선지를 더하기 위함이다.
2. answer에 -1을 하여 return gksek
-1을 하는 이유 : 옷을 안입는 경우의 수를 제거하기 위함이다.
분홍 형광펜 부분이 안입는다는 경우의 수가 되기 때문에 1을 빼준다
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] [Python] Level2_프린터 (0) | 2021.08.03 |
---|---|
[프로그래머스] [Python] Level2_기능개발 (0) | 2021.08.03 |
[프로그래머스] [Python] Level2 - 더 맵게 (2) | 2021.08.02 |
[프로그래머스] [Python] Level1_체육복 (0) | 2021.08.01 |
[프로그래머스] [Python] Level2_전화번호 목록 (0) | 2021.07.31 |
댓글