cs: add «1614. Maximum Nesting Depth of the Parentheses»

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-04-04 23:08:57 +02:00
parent 49defb257e
commit e1f7a646ae
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

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