Maximum Nesting Depth of the Parentheses

 

1614. Maximum Nesting Depth of the Parentheses

Solution

  1. The string is a valid parentheses string. We only need to count( for the number of parentheses.

  2. 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