20250730 baekjoon
This commit is contained in:
parent
abbdab565e
commit
599c65fc89
24
code_study/Baekjoon/python/30804.py
Normal file
24
code_study/Baekjoon/python/30804.py
Normal 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')
|
||||||
Loading…
x
Reference in New Issue
Block a user