Created
May 3, 2022 04:53
-
-
Save mym0404/c25526fca3ff1158828910647fac663c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T = int(input()) | |
for _ in range(T): | |
s = input() | |
n = len(s) | |
open = 0 | |
YES = True | |
for i in range(n): | |
if s[i] == '(': | |
open += 1 | |
else: | |
if open == 0: | |
YES = False | |
else: | |
open -= 1 | |
if open != 0: | |
YES = False | |
print("YES" if YES else "NO") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment