my python solution with 33 ms


  • 0
    M
    class Solution(object):
        def isValid(self, s):
            """
            :type s: str
            :rtype: bool
            """
            temp = []
            check1 = ['{', '(', '[']
            check2 = ['}', ')', ']']
            
            for i in s:
                print i, temp
                if i in check1: 
                    temp.append(i)
                elif temp == []: return False
                else:
                    loc = check2.index(i)
                    if temp.pop() != check1[loc]: return False
            
            return temp == []
    

Log in to reply
 

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