Skip to content

Instantly share code, notes, and snippets.

@hidden-pool
Last active May 27, 2025 14:43
Show Gist options
  • Save hidden-pool/140afc4ef1f2b2d575a015e03d367219 to your computer and use it in GitHub Desktop.
Save hidden-pool/140afc4ef1f2b2d575a015e03d367219 to your computer and use it in GitHub Desktop.
using System;
namespace Variables
{
internal class Program
{
static void Main(string[] args)
{
string stringChars = "(()";
char openBracket = '(';
char closBracket = ')';
int currentDepth = 0;
int maximumDepth = 0;
bool isValid = true;
foreach (char symbol in stringChars)
{
if (symbol == openBracket)
{
currentDepth++;
maximumDepth = Math.Max(maximumDepth, currentDepth);
}
else if (symbol == closBracket)
{
if (currentDepth == 0)
{
isValid = false;
break;
}
currentDepth--;
}
}
Console.WriteLine(isValid ? $"Глубина: {maximumDepth}" : "Некорректная строка");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment