class Solution: def maxDepth(self, s: str) -> int: num_open = 0 max_depth = 0 for c in s: if c == '(': num_open += 1 max_depth = max(num_open, max_depth) elif c == ')': num_open -= 1 return max_depth Complexity Time: O(n) where n is number of characters in string Space: O(1)