문제
https://school.programmers.co.kr/learn/courses/30/lessons/132265
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
코드
def solution(topping):
answer = 0
for i in range(1, len(topping)):
if len(set(topping[:i])) == len(set(topping[i:])):
answer += 1
return answer
시간 초과!
from collections import Counter
def solution(topping):
answer = 0
chelsoo = set()
brother = Counter(topping)
for i in topping:
chelsoo.add(i)
brother[i] -= 1
if brother[i] == 0:
brother.pop(i)
if len(chelsoo) == len(brother):
answer += 1
return answer
'⏳ 알고리즘 > python 알고리즘 문제 풀이' 카테고리의 다른 글
프로그래머스 - LV2. 택배상자 (0) | 2022.11.04 |
---|---|
프로그래머스 - LV1. 햄버거 만들기 (0) | 2022.10.29 |
프로그래머스 - LV3. 가장 먼 노드 (0) | 2022.10.27 |
프로그래머스 - LV3. 순위 (0) | 2022.10.27 |
프로그래머스 - LV2. 연속 부분 수열 (0) | 2022.10.21 |