您的位置:首页 > 编程语言 > Python开发

leetcode 日经贴,python code -Valid Parentheses

2015-02-10 22:38 471 查看
Valid Parentheses

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: