Skip to content

Instantly share code, notes, and snippets.

View unilecs's full-sized avatar

UniLecs unilecs

View GitHub Profile
@unilecs
unilecs / EvaluateTree.cs
Last active May 27, 2024 06:48
Задача: Бинарное булево дерево
using System;
public class Program
{
public class TreeNode
{
public int val;
public TreeNode left;
public TreeNode right;
public TreeNode(int val, TreeNode left=null, TreeNode right=null)
@unilecs
unilecs / FindMaxDepth.cs
Created May 8, 2024 05:15
Задача: Глубина скобок
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] == '(') {
@unilecs
unilecs / CountSubArrays.cs
Last active April 15, 2024 05:31
Задача: Количество подмассивов, в которых максимальный элемент встречается не менее K раз
using System;
using System.Linq;
public class Program
{
public static long CountSubArrays(int[] nums, int k) {
int len = nums.Length;
int max = nums.Max();
int start = 0;
long res = 0; int maxCountInWindow = 0;
@unilecs
unilecs / FindMinNumOfUniqueIntegers.cs
Created April 1, 2024 02:06
Задача: Наименьшее количество различных целых чисел после K удалений
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static int FindMinNumOfUniqueIntegers(int[] arr, int k) {
var map = new Dictionary<int, int>();
for (int i = 0; i < arr.Length; i++)
{
@unilecs
unilecs / FindMaxLengthBetweenEqualCharacters.cs
Last active March 17, 2024 01:57
Задача: наибольшая подстрока между двумя одинаковыми символами
using System;
using System.Collections.Generic;
public class Program
{
public static int FindMaxLengthBetweenEqualCharacters(string s) {
int maxLen = -1;
var map = new Dictionary<char, int>();
for (int i = 0; i < s.Length; i++)
{
@unilecs
unilecs / CombinationSum.cs
Created February 29, 2024 05:54
Задача: Комбинированная сумма
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
private static int Target;
public static IList<IList<int>> Output;
public static IList<IList<int>> CombinationSum(int[] candidates, int target) {
@unilecs
unilecs / DestinationCity.cs
Last active February 14, 2024 06:42
Задача: Пункт назначения
using System;
using System.Collections.Generic;
public class Program
{
public static string DestinationCity(IList<IList<string>> paths) {
int len = paths.Count;
// частный случай
if (len == 1) {
return paths[0][1];
@unilecs
unilecs / FindFreqNumber.cs
Created January 29, 2024 02:07
Задача: Часто встречаемый элемент *
using System;
public class Program
{
public static int FindFreqNumber(int[] arr)
{
int len = arr.Length;
if (len < 3)
{
return arr[0];
@unilecs
unilecs / FindLarge3DigitNum.cs
Last active January 16, 2024 03:09
Задача: Максимальное число в подстроке
using System;
public class Program
{
public static string FindLarge3DigitNum(string num)
{
string result = "";
for (int i = 0; i < num.Length - 2; i++)
{
@unilecs
unilecs / FindMissedBinaryString.cs
Created December 25, 2023 01:48
Задача: Пропущенная двоичная строка
using System;
using System.Collections.Generic;
public class Program
{
public static string ConvertNumToBinaryString(int num, int length)
{
string binary = Convert.ToString(num, 2);
// добавляем ведущие нули до размера length