精華區beta Marginalman 關於我們 聯絡資訊
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
SecondRun: 大師 04/04 15:27
digua: 大師 04/04 15:28
Rushia: 我兔了這變數也太傷眼 1 += 1 l += 1 04/05 00:50
Rushia: 我之後一定要用left 04/05 00:51