Skip to content

Instantly share code, notes, and snippets.

#nftset=/.ua/4#inet#fw4#vpn_domains
#nftset=/10minutemail.com/4#inet#fw4#vpn_domains
#nftset=/1337x.to/4#inet#fw4#vpn_domains
#nftset=/24.kg/4#inet#fw4#vpn_domains
#nftset=/4freerussia.org/4#inet#fw4#vpn_domains
#nftset=/4pda.ru/4#inet#fw4#vpn_domains
#nftset=/4pda.to/4#inet#fw4#vpn_domains
#nftset=/7dniv.rv.ua/4#inet#fw4#vpn_domains
#nftset=/9tv.co.il/4#inet#fw4#vpn_domains
#nftset=/a-msedge.net/4#inet#fw4#vpn_domains
<?php
function bump(array $asteroids) : array {
for ($i=0; $i < count($asteroids)-1; $i++) {
if ($asteroids[$i] > 0 && $asteroids[$i+1] < 0) {
if ($asteroids[$i] > abs($asteroids[$i+1])) {
unset($asteroids[$i+1]);
} else if ($asteroids[$i] < abs($asteroids[$i+1])) {
unset($asteroids[$i]);
} else {
@jamesRUS52
jamesRUS52 / example.php
Created October 30, 2020 10:15
Анонс #245. Сериализация и десериализация двоичного дерева поиска
<?php
require 'vendor/autoload.php';
use MyDataStructure\MyBinarySearchTree;
$tree = new MyBinarySearchTree();
$tree->add(4);
$tree->add(2);
$tree->add(1);
@jamesRUS52
jamesRUS52 / insert_tree_node.php
Last active October 23, 2020 08:48
#244. Вставка в двоичное дерево поиска (https://telegra.ph/Anons-244-Vstavka-v-dvoichnoe-derevo-poiska-10-23)
<?php
namespace MyDataStructure;
class MyBinarySearchTree extends MyTree
{
/**
* Добавление узла в дерево
@jamesRUS52
jamesRUS52 / sections.php
Created October 16, 2020 10:23
Перекрывающиеся интервалы (https://telegra.ph/Anons-243-Perekryvayushchiesya-intervaly-10-15)
<?php
function printSections($sections) {
foreach ($sections as $section) {
print str_pad('|',$section[0]+1,' ',STR_PAD_LEFT).str_pad('|',$section[1]-$section[0]+1,'-',STR_PAD_LEFT)." ({$section[0]}-{$section[1]})".PHP_EOL;
}
}
function sortSections($sections) {
for ($i = 0; $i < count($sections); $i++) {
for ($j = 0; $j < count($sections) - 1; $j++) {
<?php
function majority(array $array): array {
$output = [];
$count = count($array);
sort($array);
$current_element_count = 1;
for ($i = 0; $i < $count; $i++) {
if ($i !== $count-1) {
if ($array[$i] === $array[$i+1]) {
public static function restoreTree(array $preorder, array $inorder) : self {
$tree = new self();
$root = $tree->add($preorder[0]);
$tree->splitInorder($root, $preorder, $inorder);
return $tree;
}
<?php
function compareVersions(string $version1, string $version2) : int {
$parts1 = explode('.', $version1);
$parts2 = explode('.', $version2);
$diff = abs(count($parts1) - count($parts2));
if (count($parts1) > count($parts2)) {
$parts2 = array_merge($parts2, array_fill($diff-1, $diff, 0));
@jamesRUS52
jamesRUS52 / MyBinaryTree.php
Created September 19, 2020 14:26
Симметричный обход бинарного дерева
public function SymmetricOrder() : string {
$output = "";
$stack = new MyStack();
$node = $this->root;
while ($node !== null) {
if ($node->getLeft() !== null) {
$stack->push($node);
$node = $node->getLeft();
} else {
$output .= $node->getData()." ";
<?php
/**
* Разбинение строки
* https://telegra.ph/Anons-238-Razdelenie-stroki-09-10
*
* На первой итерации берем первый символ и ищем его последнее вхождение в строке
* это будет первый кусок (или по крайней мере его начало)
* Далее для каждого следующего символа остатка строки проверяем есть ли он в предыдущих уже сгенерированных кусках,
* если нет, то формируем новый кусок и по примеру первой итерации ищем его последее вхождение и так до тех пор пока