From e1f7a646ae1f8db325274bfc442da8b3b8739695 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Thu, 4 Apr 2024 23:08:57 +0200 Subject: [PATCH] =?UTF-8?q?cs:=20add=20=C2=AB1614.=20Maximum=20Nesting=20D?= =?UTF-8?q?epth=20of=20the=20Parentheses=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- ...aximum-nesting-depth-of-the-parentheses.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cs/maximum-nesting-depth-of-the-parentheses.cs diff --git a/cs/maximum-nesting-depth-of-the-parentheses.cs b/cs/maximum-nesting-depth-of-the-parentheses.cs new file mode 100644 index 0000000..656cd82 --- /dev/null +++ b/cs/maximum-nesting-depth-of-the-parentheses.cs @@ -0,0 +1,21 @@ +public class Solution { + public int MaxDepth(string s) { + int maxDepth = 0; + + int open = 0; + foreach (var c in s) { + switch (c) { + case '(': + ++open; + break; + case ')': + --open; + break; + } + + maxDepth = Math.Max(maxDepth, open); + } + + return maxDepth; + } +}