My simple python solution


  • 0
    S
    class Solution(object):
        def isValid(self, s):
            """
            :type s: str
            :rtype: bool
            """
    
            stack =  s     
            valid = True
            while valid and stack:
                if '()' in stack:
                    stack = stack.replace('()', '')
                elif '{}' in stack:
                    stack = stack.replace('{}', '')
                elif '[]' in stack:
                    stack = stack.replace('[]', '')
                else:
                    valid = False
            return valid
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.