Skip to content

Instantly share code, notes, and snippets.

View unilecs's full-sized avatar

UniLecs unilecs

View GitHub Profile
@unilecs
unilecs / FixBinaryTree.cs
Created November 6, 2023 02:56
Задача: Поправить бинарное дерево
using System;
using System.Collections.Generic;
public class Program
{
public class TreeNode
{
public int val;
public TreeNode left;
public TreeNode right;
@unilecs
unilecs / CheckWordSquare.cs
Created October 23, 2023 01:27
Задача: Квадрад слов
using System;
using System.Collections.Generic;
public class Program
{
public static bool CheckWordSquare(List<string> words)
{
int len = words.Count;
for(int i = 0; i < len; i++)
@unilecs
unilecs / ApplyDiscounts.cs
Created October 9, 2023 02:20
Задача: Цена со скидкой
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static int[] ApplyDiscounts(int[] prices)
{
int len = prices.Length;
var stack = new Stack<int>();
@unilecs
unilecs / StockSpan.cs
Created September 25, 2023 02:20
Задача: Размах цены акции
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public class StockSpan
{
private readonly Stack<(int price, int num)> stack;
public StockSpan() {
@unilecs
unilecs / FindMissingItem.cs
Last active August 20, 2023 23:59
Задача. K-й пропущенный элемент
using System;
public class Program
{
public static int FindMissingItem(int[] nums, int k) {
int len = nums.Length;
if (len == 1)
return nums[0] + k;
for (int i = 1; i < len; i++)
@unilecs
unilecs / MinSubArrayLen.cs
Last active August 6, 2023 22:40
Минимальный размер подмассива сумм
using System;
public class Program
{
public static int MinSubArrayLen(int target, int[] nums)
{
int len = nums.Length;
int left = 0;
int sum = 0;
int res = int.MaxValue;
@unilecs
unilecs / GetSingleNumber.cs
Created July 23, 2023 01:13
Задача. Единственный элемент
using System;
public class Program
{
public static int GetSingleNumber(int[] nums) {
int single = 0;
int twice = 0;
foreach (int num in nums)
{
@unilecs
unilecs / FindMarioWay.cs
Created July 9, 2023 23:07
Super Mario
using System;
public class Program
{
public static int FindMarioWay(int[][] matrix)
{
int rows = matrix.Length;
int cols = matrix[0].Length;
int[,] d = new int[rows, cols];
@unilecs
unilecs / DuplicateZeros.cs
Last active June 20, 2023 01:54
Задача: Добавить нули
using System;
public class Program
{
public static void DuplicateZeros(int[] arr)
{
int len = arr.Length;
for(int i = 0; i < len; i++)
{
if (arr[i] == 0)
@unilecs
unilecs / ArraysIntersection.cs
Last active June 4, 2023 07:36
Задача: Пересечение трех отсортированных массивов
using System;
using System.Collections.Generic;
public class Program
{
public static IList<int> ArraysIntersection(int[] arr1, int[] arr2, int[] arr3)
{
int p1 = 0, p2 = 0, p3 = 0;
var result = new List<int>();