From 599c65fc89365c39a361c81bff9ebfd9eec1f850 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Wed, 30 Jul 2025 22:32:52 +0900 Subject: [PATCH] 20250730 baekjoon --- code_study/Baekjoon/python/30804.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 code_study/Baekjoon/python/30804.py diff --git a/code_study/Baekjoon/python/30804.py b/code_study/Baekjoon/python/30804.py new file mode 100644 index 0000000..7a00af9 --- /dev/null +++ b/code_study/Baekjoon/python/30804.py @@ -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') \ No newline at end of file