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
'◦ Algorithm > Python' 카테고리의 다른 글
백준 옥상 정원 꾸미기 6198 스택 (1) | 2023.04.25 |
---|---|
백준 탑 2493 스택 (0) | 2023.04.25 |
백준 카드정렬하기 1715 그리디 (0) | 2023.04.22 |
백준 전자레인지 10162 그리디 (0) | 2023.04.22 |
프로그래머스 124 나라의 숫자 구현 (0) | 2023.04.21 |