-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution1614.go
More file actions
35 lines (30 loc) · 766 Bytes
/
solution1614.go
File metadata and controls
35 lines (30 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package solution1614
// ============================================================================
// 1614. Maximum Nesting Depth of the Parentheses
// URL: https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/
// ============================================================================
/*
$ go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/1614---Maximum-Nesting-Depth-of-the-Parentheses
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_maxDepth-24 68548447 17.46 ns/op 0 B/op 0 allocs/op
PASS
*/
func maxDepth(s string) int {
d := 0
ans := 0
for _, v := range s {
switch v {
case '(':
d++
case ')':
d--
}
if d > ans {
ans = d
}
}
return ans
}