class Solution:
# @return a boolean
def isValid(self, s):
st = []
for x in s:
if x in ('(', '[', '{'):
st.append(x)
elif len(st) > 0:
if x == ')' and st[-1] == '(' or \
x == ']' and st[-1] == '[' or \
x == '}' and st[-1] == '{':
st.pop()
else:
return False
else:
return False
return False if st else True
leetcode 日经贴,python code -Valid Parentheses
最新推荐文章于 2015-07-20 11:07:48 发布