from pickle import APPEND
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param s string字符串 
# @return bool布尔型
#
class Solution:
    def isValid(self , s: str) -> bool:
        # 初始化一个栈
        statck=[]
        for i in s:
            # 栈是空的,加入
            if len(statck)==0:
                statck.append(i)
            # 如果有配对的,弹出
            elif i==')' and statck[-1]=='(':
                statck.pop()
            elif i=='}' and statck[-1]=='{':
                statck.pop()
            elif i==']' and statck[-1]=='[':
                statck.pop() 
            # 否则加入 
            else :
                statck.append(i)
        # 栈是空的,表明都是配对的,则返回true,否则返回false
        if len(statck)==0:
            return True
        else:
            return False