题目描述:
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