-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
32-alstjr7437 #231
32-alstjr7437 #231
Conversation
๋ค๋ถ์บ ์์ ์ด์๋์์๊ตฌ๋ ๋ฏผํ์์ด |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ใ ใ ใ ใ ใ ใ ใ ใ ๊ทธ๋ฆผ ๊ฐ์๊ธฐ๋น
from collections import defaultdict, deque
import sys
def input(): return sys.stdin.readline().rstrip()
N = int(input())
fruits = list(input().split())
deq = deque()
counter = defaultdict(int)
start = 0
end = 0
max_fruits = 0
while start <= N-1:
if start == end:
end += 1
deq.append(fruits[start])
counter[fruits[start]] += 1
elif len(counter) > 2:
start += 1
popped_fruit = deq.popleft()
counter[popped_fruit] -= 1
if counter[popped_fruit] == 0: del counter[popped_fruit]
else:
if end == N: break
end += 1
deq.append(fruits[end-1])
counter[fruits[end-1]] += 1
if len(counter) <= 2 and max_fruits < len(deq):
max_fruits = len(deq)
print(max_fruits)
๋ฏผ์์ ๋ฐฐ ๋ค๋ถ์บ ์ถ์นด๋๋ฆฌ๊ตฌ
๋ง๋ผํ์๋ค๊ฐ ํํ๋ฃจ๊น์ง ๋ถํ๋๋ด์ผ~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํฌํฌ์ธํฐ๋ ์๊ฐ๋ ๋ชปํ๋ค์ ,, pr ์ฝ๊ณ ๋ถ๋ถํฉ ๋ค์ ๋ณด๊ณ ์์ต๋๋ค..!!
์ฐ์๋ ๊ตฌ๊ฐ - ํฌํฌ์ธํฐ ์ฐ๊ฒฐ๊ณ ๋ฆฌ ๋ค์ ๋จธ๋ฆฌ์ ๋ฃ๊ณ ๊ฐ๋๋ค!!
๋ค๋ถ์บ ์ถํ๋๋ฆฝ๋๋ค ~~ ๐ฅณ๐ฅณ
import sys
from collections import defaultdict
def input() : return sys.stdin.readline().rstrip()
N = int(input())
fruits = list(map(int, input().split()))
set_fruits = set(fruits)
left = 0
right = 0
fruit_count = defaultdict(int)
length = 0
while right < N:
fruit_count[fruits[right]] += 1
while len(fruit_count) > 2:
fruit_count[fruits[left]] -= 1
if fruit_count[fruits[left]] == 0:
del fruit_count[fruits[left]]
left += 1
length = max(length, right-left+1)
right += 1
์ด๋ฉ ๊ฐ์ฌํฉ๋๋ค~~~ |
๐ ๋ฌธ์ ๋งํฌ
๊ณผ์ผ ํํ๋ฃจ
โ๏ธ ์์๋ ์๊ฐ
30๋ถ
โ ํ๋ฆฐ ์ฝ๋(์๊ฐ ์ด๊ณผ)
์๋์ ๊ฐ์ด
์ด์ค ๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉ
์ด๋ ๊ฒ ์ด์ค ๋ฐ๋ณต๋ฌธ์ผ๋ก ํ๋ ์๊ฐ ์ด๊ณผ๊ฐ ๋๋๊ตฐ์..
โจ ์๋ ์ฝ๋
ํ๋์ ๋ฐ๋ณต๋ฌธ์ผ๋ก ๋ณ๊ฒฝ
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
์ฌ๋ผ์ด๋ฉ ์ผ๋์ฐ ์๊ณ ๋ฆฌ์ฆ