2024-04-04 13:06:45 +0000 UTC
Maximum Nesting Depth of the Parentheses
Categories:
Links
Code
func maxDepth(s string) int {
maxDepth := 0
curDepth := 0
for _, ch := range s {
if ch == '(' {
curDepth++
maxDepth = max(maxDepth, curDepth)
} else if ch == ')' {
curDepth--
}
}
return maxDepth
}