์ฝํ
์ค๋น
ํ๋ก๊ทธ๋๋จธ์ค. ํ๋ฒ๊ฑฐ ๋ง๋ค๊ธฐ
์๋๋ค
2023. 1. 23. 02:10
https://school.programmers.co.kr/learn/courses/30/lessons/133502#
ํ๋ก๊ทธ๋๋จธ์ค
์ฝ๋ ์ค์ฌ์ ๊ฐ๋ฐ์ ์ฑ์ฉ. ์คํ ๊ธฐ๋ฐ์ ํฌ์ง์ ๋งค์นญ. ํ๋ก๊ทธ๋๋จธ์ค์ ๊ฐ๋ฐ์ ๋ง์ถคํ ํ๋กํ์ ๋ฑ๋กํ๊ณ , ๋์ ๊ธฐ์ ๊ถํฉ์ด ์ ๋ง๋ ๊ธฐ์ ๋ค์ ๋งค์นญ ๋ฐ์ผ์ธ์.
programmers.co.kr
def solution(ingredient):
answer = 0
stack = []
for i in ingredient:
stack.append(i)
if len(stack) >= 4:
if stack[-4] == 1 and stack[-3] == 2 and stack[-2] == 3 and stack[-1] == 1:
stack.pop()
stack.pop()
stack.pop()
stack.pop()
answer += 1
return answer
"""
1 2 3 1์ด๋ฉด ans += 1
"""
๋ง ๊ทธ๋๋ 1-2-3-1์ด๋ฉด ๋ชจ๋ pop()์ ํตํด ์์ ์ฃผ๊ณ ์นด์ดํธ 1์ ๋๋ ค์ฃผ๋ฉด ๋๋ค.