1614. Maximum Nesting Depth of the Parentheses

Updated: 2024-04-15
1 min read
[]

On This Page

LeetCode problem 1614

class Solution:
    def maxDepth(self, s: str) -> int:
        stack = []
        res = 0
        for c in s:
            if c == '(':
                stack.append(1)
                res = max(res, len(stack))
            elif c == ')':
                stack.pop()
        
        return res