leetcode答案 有效的括号(python)

 1 def isValid(s):
 2     if s and len(s) % 2 is 0:
 3         a = {')': '(', ']': '[', '}': '{'}
 4         l = [None]
 5         for i in s:
 6             if i in a and a[i] == l[-1]:
 7                 l.pop()
 8             else:
 9                 l.append(i)
10         return len(l) == 1
11     elif len(s) % 2 is 1:
12         return False
13     else:
14         return True
原文地址:https://www.cnblogs.com/chaofan-/p/10414101.html