def solution(s):
answer = True
stk=[]
for i in s:
if i=='(':
stk.append(i)
elif stk and i==')' and stk[-1]=='(':
stk.pop()
else:
return False
if stk:
answer=False
else:
answer=True
return answer
def solution(s):
x = 0
for w in s:
if x < 0:
break
x = x+1 if w=="(" else x-1 if w==")" else x
return x==0