- 设立判定条件
- 遍历的范围
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
n=len(s)
for i in range(0,n-1):
if s[i]=='(' and s[i+1]!=')':
return False
if s[i]=='[' and s[i+1]!=']':
return False
if s[i]=='{' and s[i+1]!='}':
return False
return True