20250730 baekjoon

This commit is contained in:
songyc macbook 2025-07-30 22:32:52 +09:00
parent abbdab565e
commit 599c65fc89

View File

@ -0,0 +1,24 @@
import sys
input = sys.stdin.readline
print = sys.stdout.write
N = int(input())
tanghuru = list(map(int, input().split()))
fruit_count = {}
start = end = 0
maxLen = 0
while True :
if len(fruit_count) <= 2 :
maxLen = max(maxLen, end - start)
if end == N :
break
fruit_count[tanghuru[end]] = fruit_count.get(tanghuru[end],0) + 1
end += 1
else :
fruit_count[tanghuru[start]] -= 1
if fruit_count[tanghuru[start]] == 0 :
fruit_count.pop(tanghuru[start])
start += 1
print(str(maxLen)+'\n')