题解 | #合法括号序列判断#
合法括号序列判断
http://www.nowcoder.com/practice/d8acfa0619814b2d98f12c071aef20d4
-- coding:utf-8 --
class Parenthesis: def chkParenthesis(self, A, n): # write code here l = 0 for i in range(n): c = A[i] if c == '(': l+=1 elif c == ')': l=l-1 else: return False if l == 0: return True else: return False