leetcode1111

 1 class Solution:
 2     def maxDepthAfterSplit(self, seq: str) -> 'List[int]':
 3         n = len(seq)
 4         stack = []
 5         res = [0] * n
 6         odd = True
 7         for i in range(n):
 8             cur = seq[i]
 9             if len(stack) == 0 or cur == '(':
10                 stack.append((i,cur))
11             else:
12                 top = stack[-1]
13                 if top[1] == '(':
14                     if odd:
15                         res[top[0]] = 1
16                         res[i] = 1
17                     stack.pop(-1)
18                     odd = not odd
19         return res

 

上一篇:HDUOJ 4990 Reading comprehension


下一篇:Python【每日一问】34