Python solution


  • 0
    S
       stack=[]
            for i in s:
                print i
                if(i=="(" or i=="{" or i=="["):
                    stack.append(i)
                if(i==')' or i=='}' or i==']'):
                    if len(stack)==0:
                        return False
                    ele=stack.pop()
                    if( not ((ele=='(' and  i==')') or (ele=='{' and  i=='}') or (ele=='[' and  i==']') )):
                        return False
            
            if len(stack)==0:
                return True
            else:
                return False
    

Log in to reply
 

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