728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# 한 배열에 대한 조합
from itertools import combinations
# 각 원소의 중복 갯수
from collections import Counter
def solution(orders, course):
answer = []
#course에 들어가있는 i를 temp 안에 조합해준다.
for i in course:
temp = []
# 조합 반복문
for j in orders:
#들어온 주문 = j 를 i 와함께 조합한다..
c = combinations(sorted(j), i)
# 조합된 c 를 temp 에 넣어준다.
temp += c
#조합된 주문은 카운터
counter = Counter(temp)
#카운터에 값이 있고 최대값이 1이아니면 추가 추가시키기.
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)
|
cs |
728x90
반응형
'알고리즘' 카테고리의 다른 글
[ 프로그래머스 ] 섬 연결하기 (0) | 2021.09.24 |
---|---|
[ 프로그래머스 ] 구명보트 (0) | 2021.09.17 |
[ 프로그래머스 ] 큰 수 만들기 (0) | 2021.09.16 |
[ 프로그래머스 ] 카펫 (0) | 2021.09.14 |
[프로그래머스] 소수 찾기 (0) | 2021.09.14 |