반응형
programmers.co.kr/learn/courses/30/lessons/72411
코딩테스트 연습 - 메뉴 리뉴얼
레스토랑을 운영하던 스카피는 코로나19로 인한 불경기를 극복하고자 메뉴를 새로 구성하려고 고민하고 있습니다. 기존에는 단품으로만 제공하던 메뉴를 조합해서 코스요리 형태로 재구성해서
programmers.co.kr
풀이
orders에 들어있는 모든 주문에 대해서 course별로 combination을 해주었습니다.
그 다음 리스트에 전부 다 넣어주고 counter로 가장 많이 들어있는 조합을 넣어줬습니당
다른사람 풀이 보면
생각한건 똑같은데 되게 짧게 다들 잘쓰네요...
파이썬스러운 코딩을 하도록 노력해야겠습니다.
from itertools import combinations
from collections import Counter
def solution(orders, course):
answer = []
for i in course:
lst=[]
for order in orders:
order=list(order)
order.sort()
order=list(combinations(order,i))
lst=lst+order
counter=Counter(lst).most_common()
cnt=0
if len(counter)==0:
continue
elif counter[0][1]>1:
for index in range(1,len(counter)):
if counter[index][1]==counter[index-1][1]:
cnt+=1
else :
break
if cnt==0:
tmp="".join((counter[0][0]))
answer.append(tmp)
else:
for j in range(cnt+1):
tmp="".join((counter[j][0]))
answer.append(tmp)
answer.sort()
return(answer)
반응형
'알고리즘 > 문제 풀이' 카테고리의 다른 글
[Python/파이썬 1107 백준] 리모컨 (0) | 2021.05.20 |
---|---|
[Python/파이썬 프로그래머스] 광고 삽입 (0) | 2021.05.19 |
[Python/파이썬 프로그래머스] 보석 쇼핑 (0) | 2021.05.06 |
[Python/파이썬 프로그래머스] 키패드 누르기 (0) | 2021.05.04 |
[Python/파이썬 프로그래머스] 호텔 방 배정 (0) | 2021.05.04 |