293. 겹치는 건 싫어

아현·2021년 9월 7일
0

Algorithm

목록 보기
307/400

백준




1. 투포인터


import collections
n, k = map(int, input().split())

array = list(map(int, input().split()))
count = collections.defaultdict(int)

right = 0
left = 0
result = 0

while right < n:
    if count[array[right]] != k:
        count[array[right]] += 1
        right += 1
    else:
        count[array[left]] -= 1
        left += 1
    
    result = max(result, right - left)

print(result)



profile
Studying Computer Science

0개의 댓글