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 | 31 |
Tags
- BFS
- 파이썬
- 코딩테스트
- 힙
- programmers
- BOJ
- 구현
- 가상메모리
- dfs
- DP
- 브루트포스
- python
- dict
- 그리디
- 백준
- 다익스트라
- 운영체제
- 수학
- level2
- MYSQL
- level1
- level0
- level3
- 가상메모리 관리
- 재귀
- 스택
- N과M
- 딕셔너리
- 프로그래머스
- 다이나믹 프로그래밍
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 |