Created
May 8, 2024 05:15
-
-
Save unilecs/e6950404e6328cbc6a517b379ba1b8a1 to your computer and use it in GitHub Desktop.
Задача: Глубина скобок
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static int FindMaxDepth(string s) { | |
int depth = 0; | |
int curDepth = 0; | |
for (int i = 0; i < s.Length; i++) | |
{ | |
if (s[i] == '(') { | |
curDepth++; | |
} else if (s[i] == ')') { | |
curDepth--; | |
} | |
depth = Math.Max(depth, curDepth); | |
} | |
return depth; | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
// tests | |
Console.WriteLine(FindMaxDepth("(1+(2*3)+((8)/4))+1").ToString()); // 3 | |
Console.WriteLine(FindMaxDepth("(1)+((2))+(((3)))").ToString()); // 3 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment