๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/12973
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 2๋จ๊ณ - 2017ํ์คํ์ด - ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ
def solution(s):
stack = []
for i in s:
if not stack: # stack์ด ๋น์ด์์ ๊ฒฝ์ฐ stack์ push
stack.append(i)
elif stack[-1] == i: # stack์ ๋ง์ง๋ง ์์์ s์์ pop๋๋ ์์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ
stack.pop()
else: # stack์ ๋ง์ง๋ง ์์์ pop๋๋ ์์๊ฐ ๋ค๋ฅธ ๊ฒฝ์ฐ ๊ทธ ์์๋ฅผ stack์ ์ถ๊ฐ
stack.append(i)
answer = -1
return answer
์คํ ์ด๋ผ๋ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์๊ฐํ๊ณ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] [2018 KAKAO BLIND RECRUITMENT] [Python] Level2_[1์ฐจ]์บ์ (0) | 2022.10.12 |
---|---|
[Programmers] [ํ์๋ฒ(Greedy)] [Python] Level2_๊ตฌ๋ช ๋ณดํธ (0) | 2022.10.12 |
[Programmers] [์์ ํ์] [Python] Level2_์นดํซ (0) | 2022.10.09 |
[Programmers] [์ฐ์ต๋ฌธ์ ] [Python] Level2_์ซ์์ ํํ (0) | 2022.10.09 |
[Programmers] [์คํ/ํ] [Python] Level2_์ฌ๋ฐ๋ฅธ ๊ดํธ (0) | 2022.10.06 |