일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 프로그래머스
- backjoon
- 재귀함수
- 위클리 챌린지
- 추석맞이 코딩챌린지
- Zip
- Re
- divmod
- BFS
- Set
- 그리디
- KAKAO BLIND RECRUITMENT
- DateTime
- python
- Combinations
- 수학
- heapq
- 카카오
- java
- 파이썬
- 동적 계획법
- 정렬
- 백준
- 이분탐색
- 정규식
- 자바
- lambda
- 다익스트라
- dfs
- programmers
Archives
- Today
- Total
상상쓰
[프로그래머스] 위장 본문
https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장
programmers.co.kr
처음에는 combinations 를 이용하여 풀었는데 시간 초과가 났다. 다시 보니, 조합을 이용할 필요가 없었다.
headgear 가 3가지 종류가 있다면 headgear 를 안 쓰는 조건까지 추가하여 4가지로 계산한다. 최소한 한 개 이상의 의상은 입으므로 최종적으로 계산된 answer 에서 아무것도 안 입는 경우인 1을 빼주면 된다.
from collections import defaultdict
def solution(clothes):
answer = 1
dic = defaultdict(int)
for i in clothes:
dic[i[1]] += 1
N = len(dic.keys())
for i in dic.keys():
answer *= dic[i] + 1
return answer - 1
print(solution([['yellowhat', 'headgear'], ['bluesunglasses', 'eyewear'], ['green_turban', 'headgear']])) # 5
'Coding Test' 카테고리의 다른 글
[백준] 라디오 (0) | 2021.06.28 |
---|---|
[백준] A → B (0) | 2021.06.26 |
[프로그래머스] 짝지어 제거하기 (0) | 2021.06.23 |
[프로그래머스] 다단계 칫솔 판매 (0) | 2021.06.23 |
[프로그래머스] 매칭 점수 (0) | 2021.06.22 |
Comments