1614. Maximum Nesting Depth of the Parentheses
Solution
-
The string is a valid parentheses string. We only need to count
(
for the number of parentheses. -
Remember to update the result if possible.
def maxDepth(self, s):
res = cur = 0
for c in s:
if c == '(':
cur += 1
res = max(res, cur)
if c == ')':
cur -= 1
return res