Python Solution


  • 0
    C

    '''
    class Solution(object):
    def isValid(self, s):
    """
    :type s: str
    :rtype: bool
    """

        bracket_dict = {'[':']', '{':'}', '(':')'}
        stack = []
    
        for char in s:
            if char in bracket_dict.keys():
                stack.append(char)
            elif char in bracket_dict.values():
                if len(stack) == 0 or char != bracket_dict[stack.pop()]:
                    return False
            else:
                return False
        return len(stack) == 0
    

    '''


Log in to reply
 

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