编写一个调用的函数,该函数接受一个括号字符串,并确定括号的顺序是否有效

题目描述:

  

Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. 
The function should return true if the string is valid, and false if it's invalid.

我的解答:
  
def valid_parentheses(string):
conn = 0
for i in string:
if i == '(':
conn += 1
if i == ')':
conn -= 1
if conn < 0:
return False
if conn == 0:
return True
else:
return False
原文地址:https://www.cnblogs.com/wlj-axia/p/12692338.html