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