class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
check=[]
if len(s)%2==1:
return False
for i in range(0,len(s)):
if len(check)>0:
if (check[top]=='{' and s[i] == '}') or (check[top]=='(' and s[i] == ')') or (check[top]=='[' and s[i] == ']'):
top=len(check)-1
del check[top]
else:
check.append(s[i])
else:
check.append(s[i])
if len(check)==0:
return True
else:
return False
网友评论