1. Problem
2. My Solution
import sys
test_n = int(sys.stdin.readline().strip())
for _ in range(test_n):
ps = sys.stdin.readline().strip()
for _ in range(len(ps)//2):
ps = ps.replace("()","")
if len(ps) == 0:
print('YES')
else:
print('NO')
3. Others' Solutions
def solve():
data = input()
stack = []
for item in data:
if item == '(':
stack.append(item)
else:
if len(stack) == 0:
print("NO")
return
else:
stack.pop()
if len(stack) == 0:
print("YES")
else:
print("NO")
4. Learned
1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline().strip())
sequence = []
stack = []
push_pop = []
for _ in range(n):
sequence.append(int(sys.stdin.readline().strip()))
i = 0
j = 0
flag = True
while(i != n or len(stack)!=0):
try:
if stack[-1] > sequence[j]:
flag = False
break
elif stack[-1] == sequence[j]:
stack.pop()
push_pop.append("-")
j += 1
else:
i += 1
stack.append(i)
push_pop.append("+")
except:
i += 1
stack.append(i)
push_pop.append("+")
if flag == True:
for i in push_pop:
print(i)
else:
print("NO")
3. Learned