s = "(())"
stack = []
is_valid = True
for ch in s:
if ch == '(':
stack.append(ch)
else:
if not stack:
is_valid = False
break
stack.pop()
if stack:
is_valid = False
print(is_valid)
To embed this project on your website, copy the following code and paste it into your website's HTML: