1 class Solution:
 2     def minAddToMakeValid(self, S):
 3         """
 4         :type S: str
 5         :rtype: int
 6         """
 7         stack = []
 8         S = list(S)
 9         for s in S:
10             if len(stack) != 0:
11                 if s == ")" and stack[-1] == "(":
12                     stack.pop()
13                 else:
14                     stack.append(s)
15             else:
16                 stack.append(s)
17         return len(stack)

击败了百分之百的人,纪念一下。

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!