Go Nesting
func nesting(s string) int {
if s == "" {
return 1
}
depth := 0
for i := 0; i < len(s); i++ {
if s[i] == ')' {
if depth == 0 {
return 0
}
depth--
} else {
depth++
}
}
if depth == 0 {
return 1
}
return 0
}
This treats the string like a balance counter: open parentheses add one, closing ones remove one.