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; + } +}