Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Apr 4, 2024
1 parent d93b8dc commit d721b07
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions leetcode/1614.MaximumNestingDepthoftheParentheses/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/

package main

import (
"fmt"
)

func maxDepth(s string) int {
res := 0
d := 0
for _, c := range s {
if c == '(' {
d++
res = max(res, d)
} else if c == ')' {
d--
}
}
return res
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func main() {
s := "(1+(2*3)+((8)/4))+1"
fmt.Println(maxDepth(s))
}

0 comments on commit d721b07

Please sign in to comment.