🔈 첫번째 풀이
def solution(s):
stac = []
for x in s:
print(stac)
if x == '(':
stac.append(x)
else:
if not stac:
return False
else:
stac.pop()
if stac:
return False
return True
🔉 코드리뷰를 가진 풀이
- 오퍼레이터 사이는 띄워야 한다.
if stac: return False return True
위 코드를 아래로 수정
return if stac == []
def solution(s):
stack = []
for x in s:
if x == '(':
stack.append(x)
else:
if not stack:
return False
else:
stack.pop()
return if stack == []
🔊 리더님 코드
def solution(s):
c = 0
for x in s:
if x == '(':
c += 1
else:
c -= 1
if c < 0:
return False
return c == 0