Solution in Python.


  • 0
    Z
    class Solution:
        def isValid(self, s):
            pars = [None]
            parmap = {')':'(', '}':'{', ']':'['}
            for c in s:
                if c in parmap and parmap[c] == pars[len(pars) - 1]:
                    pars.pop()
                else:
                    pars.append(c)
            return len(pars) == 1
    

Log in to reply
 

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