|
์ฝ๋ ์์ฑํ๊ธฐ
def solution(s):
cnt = 0
for i in s:
if cnt < 0:
return False
if i == '(':
cnt += 1
else:
cnt -= 1
return cnt == 0
Python
๋ณต์ฌ
|
์ฝ๋ ์ค๋ช
ํ๊ธฐ
for ๋ฌธ์์ด:
cnt๊ฐ ์์์ด๋ฉด False
(์ด๋ฉด cnt 1์ ๋ํ๋ค.
)์ด๋ฉด cnt 1์ ๋บ๋ค.
cnt๊ฐ 0์ด๋ฉด true, ์๋๋ฉด false