s = list(input())
you = []
stack = []
for x in s:
if x=='(' or x==')'or x=='['or x==']':
you.append(x)
if len(you)%2==0 and you[0] != ']'and you[0]!=')':
for x in you:
if x == '(' or x == '[':
stack.append(x)
elif (x == ')' and stack[len(stack)-1] == '(') or (x == ']' and stack[len(stack)-1] == '['):
stack.pop()
else:
break
if len(stack)==0:
print("true")
else:
print("false")
else:
print("false")
遍历取数浪费了时间,但可以len(you)%2==0 and you[0] != ']'and you[0]!=')'可以节约判断遍历时间

京公网安备 11010502036488号