본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 23175번 Histogram Sequence 3

by 현장 2023. 6. 16.

-Code

m = int(input())
sequence = list(map(int, input().split()))
res = []
pointer, cnt = 0, 0
for n in sequence:
    if pointer != n:
        pointer = n
        cnt = 1
    if cnt == pointer:
        res.append(n)
        pointer, cnt = 0, 0
    if pointer == n:
        cnt += 1
print(*res)