Re: [闲聊] 每日leetcode

楼主: sustainer123 (caster)   2024-04-04 15:22:40
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
作者: SecondRun (雨夜琴声)   2024-04-04 15:27:00
大师
作者: digua (地瓜)   2024-04-04 15:28:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com