SHARE
TWEET

Untitled

a guest Dec 16th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def isValid(self, s):
  2.  
  3.         if not s:
  4.             return True
  5.        
  6.         dict = {'(':')', '[':']', '{':'}'}
  7.         list = []
  8.        
  9.         if s[0] in dict.values():
  10.             return False
  11.        
  12.         for i in range(len(s)):
  13.             if s[i] in dict.keys():
  14.                 list.append(s[i])
  15.             if s[i] in dict.values() and len(list) == 0:
  16.                 return False
  17.             if s[i] in dict.values() and dict[list.pop()] != s[i]:
  18.                 return False
  19.        
  20.         if len(list):
  21.             return False
  22.        
  23.         return True
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top