题解 | 只有两种字符, 用计数器模拟栈即可, 无需额外空间
括号匹配深度
https://www.nowcoder.com/practice/cf1572d8558c4d349fb86c4a529c3cc4
seqence = input()
def get_match_depth(seq: str) -> int:
if not seq:
return 0
temp = 0
maxl = 0
for s in seq:
if s == '(':
temp += 1
if s == ')':
temp -= 1
maxl = max(maxl, temp)
return maxl
print(get_match_depth(seqence))

查看24道真题和解析