#coding=utf-8
# 解题思路:栈 20190302 找工作期间
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
stack = []
for i in s :
if i == "(" or i == "{" or i == "[":
stack.append(i)
else:
if len(stack) == 0:
return False
else:
match = None
topItem = stack.pop()
if i == ')':
match = '('
if i == ']':
match = '['
if i == '}':
match = '{'
if topItem != match:
return False
if len(stack) > 0:
return False
else:
return True
s = Solution()
print s.isValid("()")