출처 : 프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/72411
그냥 짜는게 방법이라는걸 확신하는게 가장 어려운 것 같다.
더보기
풀이
from itertools import combinations
from collections import Counter
def solution(orders, course):
answer = []
combi_list = []
for order in orders:
for num in course:
combi_list += list(set("".join(sorted(combi)) for combi in combinations(order, num)))
combi_result = sorted(list([k, v] for k, v in Counter(combi_list).items() if v != 1), key = lambda x: (len(x[0]), -x[1]))
prev_len = 0
prev_max = 0
for string, count in combi_result:
if prev_len != len(string):
answer.append(string)
prev_max = count
prev_len = len(string)
else:
if prev_max == count:
answer.append(string)
return sorted(answer)
풀이가 너무 드럽다..
Github
'알고리즘 > Python' 카테고리의 다른 글
[python] 프로그래머스 - 두 큐 합 같게 만들기 (0) | 2023.03.10 |
---|---|
[python] 프로그래머스 - 괄호 변환 (0) | 2023.03.10 |
[python] 프로그래머스 - 오픈채팅방 (0) | 2023.03.09 |
[python] 프로그래머스 - k진수에서 소수 개수 구하기 (0) | 2023.03.09 |
[python] 프로그래머스 - 튜플 (0) | 2023.03.09 |