Re: [閒聊] 每日leetcode已回收
看板Marginalman作者sustainer123 (caster )時間1年前 (2024/04/04 15:22)推噓1(1推 0噓 3→)留言4則, 3人參與討論串92/1548 (看更多)
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
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.43.142.178 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1712215363.A.435.html
推
04/04 15:27,
1年前
, 1F
04/04 15:27, 1F
→
04/04 15:28,
1年前
, 2F
04/04 15:28, 2F
→
04/05 00:50,
1年前
, 3F
04/05 00:50, 3F
→
04/05 00:51,
1年前
, 4F
04/05 00:51, 4F
討論串 (同標題文章)
完整討論串 (本文為第 92 之 1548 篇):