문제) 프로그래머스 - Hash - 위장
https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장
programmers.co.kr
옷 별로 개수를 세어줍니다. 각 옷의 개수만큼 곱해준 다음에 1을 빼면 구할 수 있습니다.
Python 소스코드)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(clothes): | |
cloth_dict = {} | |
for c, a in clothes: | |
if a in cloth_dict.keys(): | |
cloth_dict[a].append(c) | |
else: | |
cloth_dict.setdefault(a, [c]) | |
answer = 1 | |
for a in cloth_dict: | |
answer *= len(cloth_dict[a]) + 1 | |
return answer - 1 |
반응형
'PS(Problem Solving) > 프로그래머스_Programmers' 카테고리의 다른 글
[프로그래머스] 코딩테스트 고득점 Kit - 네트워크 (C++) 문제 및 풀이 (0) | 2021.12.07 |
---|---|
[프로그래머스] 코딩테스트 고득점 Kit - 주식 가격 (C++) 문제 및 풀이 (0) | 2021.12.04 |
[프로그래머스] 코딩테스트 고득점 Kit - 더 맵게 (C++) 문제 및 풀이 (0) | 2021.12.02 |
[프로그래머스] 코딩테스트 고득점 Kit - 모의고사 (Python) 문제 및 풀이 (0) | 2021.12.01 |
[프로그래머스] 2021 카카오 채용연계형 인턴십 - 거리두기 확인하기 (파이썬) 문제 및 풀이 (0) | 2021.08.04 |
댓글