10 liner python regex solution using replace()


  • 0
    P

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

        while True:
            a = s == s.replace("()","")
            s = s.replace("()","")
            b = s == s.replace("{}","")
            s = s.replace("{}","")
            c = s == s.replace("[]","")
            s = s.replace("[]","")
            if a and b and c:
                break
        return s == ""

Log in to reply
 

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