July 26, 2021
def solution(s):
stack = []
for p in s:
if p == '(':
stack.append(p)
else:
if stack:
if stack[-1] == '(':
stack.pop(-1)
else:
stack.append(p)
return len(stack) == 0
def is_pair(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
def solution(s):
x = 0
for w in s:
if x < 0:
break
if w == "(":
x = x + 1
elif w == ")":
x = x - 1
else:
continue
return x == 0