레벨2 문제
from itertools import combinations
def solution(orders, course):
arr = []
for num in course:
dic = {}
for i in range(len(orders)):
orders[i] = list(orders[i])
orders[i].sort()
for j in combinations(orders[i], num):
if j in dic:
dic[j] += 1
else:
dic[j] = 1
if (len(dic) == 0):
continue
imax = max(dic.values())
for k in dic:
if ( dic[k] >= 2 and dic[k] == imax):
arr.append("".join(k))
arr.sort()
answer = arr
return answer
from itertools import combinations
from collections import Counter
def solution(orders, course):
arr = []
for num in course:
basket = []
for i in range(len(orders)):
orders[i] = list(orders[i])
orders[i].sort()
for j in combinations(orders[i], num):
basket.append(j)
basket = Counter(basket)
if len(basket) == 0:
continue
imax = max(basket.values())
for k in basket:
if (basket[k] >= 2 and basket[k] == imax):
arr.append("".join(k))
arr.sort()
return arr