classSolution(object): defisValid(self, s): """ :type s: str :rtype: bool """ pstack = [] pleft = set(['(', '[', '{']) for c in s: if c in pleft: pstack.append(c) elif c == ')': if pstack == [] or pstack.pop() != '(': returnFalse elif c == ']': if pstack == [] or pstack.pop() != '[': returnFalse elif c == '}': if pstack == [] or pstack.pop() != '{': returnFalse return len(pstack) == 0