Skip to content

LC 1614 [E] Maximum Nesting Depth of the Parentheses

Code with Senpai edited this page Feb 15, 2022 · 1 revision
class Solution:
    def maxDepth(self, s: str) -> int:
        res = 0
        depth = 0
        
        for c in s:
            if c == '(':
                depth += 1
                res = max(res, depth)
            elif c == ')':
                depth -= 1
                
        return res
Clone this wiki locally