https://school.programmers.co.kr/learn/courses/30/lessons/132265
from collections import defaultdict
def solution(topping):
answer = 0
my = set()
# 동생이 롤케이크를 전부 보유한 상태로 INIT
d = defaultdict(int)
for i in topping:
d[i] += 1
# 철수가 0~idx 까지 롤케이크 소유
for idx in range(len(topping)):
curr = topping[idx]
d[curr] -= 1
if d[curr] == 0:
del d[curr]
my.add(curr)
if len(my) == len(d.keys()):
answer += 1
return answer
빵이 분할되는 조건은 하나의 포인터만 필요하다.
동생이 모든 빵을 다 가지고 있는 상태로 초기값을 설정하고, 철수가 0번째 인덱스부터 한 칸씩 증가시키면서 매 조건문마다 정답 조건을 검사한다.