Skip to content

Instantly share code, notes, and snippets.

@mym0404
Created May 3, 2022 04:53
Show Gist options
  • Save mym0404/c25526fca3ff1158828910647fac663c to your computer and use it in GitHub Desktop.
Save mym0404/c25526fca3ff1158828910647fac663c to your computer and use it in GitHub Desktop.
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