Files
LeetCode-Go/leetcode/1614.Maximum-Nesting-Depth-of-the-Parentheses/1614. Maximum Nesting Depth of the Parentheses.go
YDZ 14d0942f5a 1. Add solution 1091、1614、1619、1624、1629、1636、1704
2. ctl strings.TrimSpace question.Title
2021-02-15 11:37:57 +08:00

22 lines
254 B
Go

package leetcode
func maxDepth(s string) int {
res, cur := 0, 0
for _, c := range s {
if c == '(' {
cur++
res = max(res, cur)
} else if c == ')' {
cur--
}
}
return res
}
func max(a, b int) int {
if a > b {
return a
}
return b
}