valid parantheses


  • 0
    S
    class Solution(object):
        def isValid(self, s):
            """
            :type s: str
            :rtype: bool
            """
            l = []
            d = {')':'(', '}':'{', ']':'['}
            try:
                for c in s:
                    if c in d.values():
                        l.append(c)
                    else:
                        assert l.pop() == d[c]
            except:
                return False
    
            return len(l) == 0
    

Log in to reply
 

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