Re: [閒聊] 每日leetcode已回收

看板Marginalman作者 (caster )時間1年前 (2024/04/04 15:22), 編輯推噓1(103)
留言4則, 3人參與, 1年前最新討論串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
我兔了這變數也太傷眼 1 += 1 l += 1
04/05 00:50, 3F

04/05 00:51, 1年前 , 4F
我之後一定要用left
04/05 00:51, 4F
文章代碼(AID): #1c3bL3Gr (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1c3bL3Gr (Marginalman)