Maximum Nesting Depth of the Parentheses LeetCode solution in Python

1
class Solution:
2
def maxDepth(self, s: str) -> int:
3
ans = cur = 0
4
for c in s:
5
if c == "(":
6
cur += 1
7
ans = max(ans, cur)
8
elif c == ")":
9
cur -= 1
10
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0