class Solution:
    def isValid(self , s: str) -> bool:
        # write code here
        stack=[]
        for i in range(0,len(s)):
           c=s[i]
           if c=='(' or c=='{' or c=='[':
               stack.append(c)
           elif c==')': 
               
               if stack==[] or stack.pop()!='(':
                   return False
           elif c=='}': 
               if stack==[] or stack.pop()!='{':
                   return False
           elif c==']': 
               if stack==[] or stack.pop()!='[':
                   return False

        if stack!=[]:
            return False
        
        return True