🤑풀이
import pandas as pd
def solution(stones, k) :
return int(min(list(pd.Series(stones).rolling(k).max())[k-1:]))
👩🏫 아이디어
🤑풀이
from itertools import combinations
def solution(orders, course):
info = {}
for set_menu in orders :
for n in course :
# course의 개수만큼 메뉴 조합 생성
if len(set_menu) < n :
break
new_combi = combinations(set_menu, n)
for new_set in new_combi :
new_set = ''.join(sorted(new_set))
info[new_set] = info.get(new_set, 0) + 1
# 주문 정보를 담은 dictionary
# {"메뉴 개수" : {max : 주문 수, lst : max 주문수가 일치하는 세트들의 모음 }
order = {}
for i in course :
order[i] = {'max' : 0, 'lst' : []}
for cor in info :
menu_cnt, order_cnt = len(cor), info[cor]
if order[menu_cnt]['max'] < order_cnt :
order[menu_cnt]['max'] = order_cnt
order[menu_cnt]['lst'] = [cor]
elif order[menu_cnt]['max'] == order_cnt :
order[menu_cnt]['lst'].append(cor)
answer_lst = []
for i in order :
if order[i]['max'] > 1 :
answer_lst.extend(order[i]['lst'])
return sorted(answer_lst)
👩🏫 아이디어
Counter.most_common