본문 바로가기
프로그래머스/2단계

(Python/LV2) 메뉴 리뉴얼

by windy7271 2022. 10. 6.
728x90
반응형

문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/72411

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

풀이:

다른 분의 풀이를 참고했다... 맨 마지막 if 문땜에 어쩔수 없었다

from itertools import combinations
from collections import Counter


def solution(orders, course):
    answer = []
    
    for c in course:
        temp = []
        
        for order in orders:
            combi = combinations(sorted(order), c)
            temp += combi
            
        counter = Counter(temp)
        
        if len(counter) != 0 and max(counter.values()) != 1:
            answer += [''.join(f) for f in counter if counter[f] == max(counter.values())]

    return sorted(answer)

출처: https://ljhyunstory.tistory.com/19 [오늘도 컴돌이!:티스토리]

 

또 다른 풀이

참고 :https://www.youtube.com/watch?v=PnXovk2JtU4

 

반응형

댓글