Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 프로그래머스
- 수학
- dict
- 재귀
- 코딩테스트
- 백준
- N과M
- 구현
- BFS
- 다익스트라
- BOJ
- level1
- 스택
- 딕셔너리
- 브루트포스
- MYSQL
- 가상메모리
- 운영체제
- dfs
- python
- 파이썬
- level0
- 다이나믹 프로그래밍
- 그리디
- 가상메모리 관리
- DP
- level2
- level3
- 힙
- programmers
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [위장] 파이썬 본문
https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장
programmers.co.kr
#프로그래머스 위장
def solution(clothes):
answer = 1
lst={}
for clothe in clothes:
if clothe[1] in lst:
lst[clothe[1]]+=1
else:
lst[clothe[1]]=1
for val in lst.values():
answer*=(val+1)
return (answer-1)
세트( '{}' )을 이용하여 문제를 해결하였다.
def solution(clothes):
from collections import Counter
from functools import reduce
cnt = Counter([kind for name, kind in clothes])
answer = reduce(lambda x, y: x*(y+1), cnt.values(), 1) - 1
return answer
내장 함수를 이용하여 문제를 해결하는 방식도 존재한다.
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [더 맵게] 파이썬 (0) | 2021.12.11 |
---|---|
프로그래머스 level2 [오픈채팅방] 파이썬 (0) | 2021.12.10 |
프로그래머스 level2 [카펫] 파이썬 (0) | 2021.12.10 |
프로그래머스 level2 [문자열 압축] 파이썬 (0) | 2021.12.09 |
프로그래머스 level2 [방문 길이] 파이썬 (0) | 2021.12.09 |