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