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