[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ
1. ๋ฌธ์ : Link
์ฐ์๋๋ ๋ฌธ์๋ฅผ ์ฐพ์ ์ ๊ฑฐํด์ฃผ๋ ๋ฌธ์
2. ํ์ด
์คํ์ผ๋ก ํ์ด์ผํ๋ ๊ฑด ์์์ง๋ง ๋น ๋ฆฌ์คํธ๊น์ง ์๊ฐํด๋๊ณ ๊ฑฐ๊ธฐ์ appendํ๋ ๋ฐฉ์์ ๋๋ฌด ์ด์ํ๊ฒ ์๊ฐํ๋ค.
๊ธฐ๋ณธ์ ์ถฉ์คํ ์ฝ๋๋ฅผ ์ง๋๋ก ํ์.
๊ตณ์ด ์ฌ๊ท๋ก ๋๋ฆด ํ์ ์์๋ ๋ฌธ์ ์๋ค.
3. ์ฝ๋
1)
def check1(p):
tmp = []
origin = p.copy()
while p:
if len(p) == 1:
tmp.append(p.pop())
break
first = p.pop()
second = p.pop()
if first != second:
tmp.append(first)
p.append(second)
if not tmp:
return 1
tmp.reverse()
if origin == tmp:
return 0
return check1(tmp)
def solution(s):
ss = list(s)
result = check1(ss)
return result
2)
def solution(s):
stack = []
for i in s:
if len(stack) == 0:
stack.append(i)
elif stack[-1] == i:
stack.pop()
else:
stack.append(i)
if len(stack) == 0:
return 1
else:
return 0
'๐ป Coding Problems Solving > Stack | Queue' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ํ๋ฆฐํฐ (์๋ฐ java) (0) | 2023.02.22 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ฌ๋ฐ๋ฅธ ๊ดํธ (์๋ฐ java) (0) | 2022.11.25 |
[BOJ 2504] ๊ดํธ์ ๊ฐ (0) | 2022.06.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ (0) | 2022.04.15 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๋ ๋งต๊ฒ (0) | 2022.04.08 |
์ต๊ทผ๋๊ธ