cs: add «1614. Maximum Nesting Depth of the Parentheses»
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
49defb257e
commit
e1f7a646ae
1 changed files with 21 additions and 0 deletions
21
cs/maximum-nesting-depth-of-the-parentheses.cs
Normal file
21
cs/maximum-nesting-depth-of-the-parentheses.cs
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue