Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created May 8, 2024 05:15
Show Gist options
  • Save unilecs/e6950404e6328cbc6a517b379ba1b8a1 to your computer and use it in GitHub Desktop.
Save unilecs/e6950404e6328cbc6a517b379ba1b8a1 to your computer and use it in GitHub Desktop.
Задача: Глубина скобок
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