https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses
1614. Maximum Nesting Depth of the Parentheses
叙述很长 但其实不太重要
思路:
计算() 遇(+1 更新最大深度 遇)-1
Python Code:
class Solution:
def maxDepth(self, s: str) -> int:
l = ans = 0
for e in s:
if e == "(":
l += 1
ans = max(l,ans)
elif e == ")":
l -= 1
return ans