From d721b07a634e5175cd2e93de0da6c80054c54470 Mon Sep 17 00:00:00 2001 From: ductnn Date: Thu, 4 Apr 2024 22:25:21 +0700 Subject: [PATCH] add sol --- .../sol.go | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 leetcode/1614.MaximumNestingDepthoftheParentheses/sol.go diff --git a/leetcode/1614.MaximumNestingDepthoftheParentheses/sol.go b/leetcode/1614.MaximumNestingDepthoftheParentheses/sol.go new file mode 100644 index 0000000..481f016 --- /dev/null +++ b/leetcode/1614.MaximumNestingDepthoftheParentheses/sol.go @@ -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)) +}