◦ Algorithm/Python
프로그래머스 의상 딕셔너리/해시/맵/카운터
밍블리s2
2023. 4. 22. 19:17
https://school.programmers.co.kr/learn/courses/30/lessons/42578?language=python3
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
- 해당 의상 종류(type)를 입지 않는 경우를 포함해서 조합 계산
- answer *= (map[type] + 1)
딕셔너리 사용
def solution(clothes):
map = {}
for name, type in clothes:
map[type] = map.get(type, 0) + 1
answer = 1
for type in map:
answer *= (map[type] + 1)
return answer-1
카운터 사용
from collections import Counter
def solution(clothes):
map = dict(Counter([type for name, type in clothes]))
answer = 1
for type in map:
answer *= (map[type] + 1)
return answer-1