Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hw10 #582

Open
wants to merge 1 commit into
base: MMelnyk/hw1
Choose a base branch
from
Open

hw10 #582

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ https://otus.ru/lessons/razrabotchik-php/?utm_source=github&utm_medium=free&utm_

# Задание

Docker
1. Установить Docker себе на локальную машину
2. Описать инфраструктуру в Docker-compose, которая включает в себя
3. nginx (обрабатывает статику, пробрасывает выполнение скриптов в fpm)
4. php-fpm (соединяется с nginx через unix-сокет)
5. redis (соединяется с php по порту)
6. memcached (соединяется с php по порту)
7. БД подключать как отдельную VM (можно на базе Homestead), либо как контейнер (но тогда не забудьте про директории с данными)
8. Не забудьте про Composer
Решить задачу https://leetcode.com/problems/merge-two-sorted-lists/ на слияние двух списков


## Описание/Пошаговая инструкция выполнения домашнего задания:
- Решаем задачу
- Прикладываем код на GitHub
- Обосновываем сложность

## Критерии оценки:
- Решение имеет оптимальную сложность
- Учтены исключительные случаи
- Решение проходит тесты

# Установка

Expand Down Expand Up @@ -41,9 +44,7 @@ cd application && cp .env.example .env
sudo docker compose up -d
```

Добавьте сайт `mysite.local` в файл `hosts`
Для проверки алгоритма запустите следующую команду:
```bash
127.0.0.1 mysite.local
sudo docker container exec -it myapp-php-dev bash -c "cd /data/www && php console/app.php"
```

Готово!
57 changes: 57 additions & 0 deletions application/console/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

class ListNode

Check failure on line 3 in application/console/app.php

View workflow job for this annotation

GitHub Actions / phpcs

Each class must be in a namespace of at least one level (a top-level vendor name)
{
public int $val = 0;
public ?ListNode $next = null;

public function __construct($val = 0, $next = null)
{
$this->val = $val;
$this->next = $next;
}
}

class Solution {

Check failure on line 15 in application/console/app.php

View workflow job for this annotation

GitHub Actions / phpcs

Each class must be in a file by itself

Check failure on line 15 in application/console/app.php

View workflow job for this annotation

GitHub Actions / phpcs

Each class must be in a namespace of at least one level (a top-level vendor name)

Check failure on line 15 in application/console/app.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace of a class must be on the line after the definition
public function mergeTwoLists(ListNode $list1, ListNode $list2): ListNode {

Check failure on line 16 in application/console/app.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace should be on a new line
$start = $currentListNode = new ListNode();

while ($list1 && $list2) {
if ($list1->val <= $list2->val) {
$new = new ListNode($list1->val, null);
$currentListNode->next = $new;
$currentListNode = $new;
$list1 = $list1->next;
} else {
$new = new ListNode($list2->val, null);
$currentListNode->next = $new;
$currentListNode = $new;
$list2 = $list2->next;
}
}

if ($list1 || $list2) {
$currentListNode->next = $list1 ?? $list2;
}

return $start->next;

Check failure on line 37 in application/console/app.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected at least 8 spaces, found 7
}
}

// 4 - 2 - 1
$list1 = new ListNode(4);
$list1 = new ListNode(2, $list1);
$list1 = new ListNode(1, $list1);

// 5 - 2 - 1
$list2 = new ListNode(5);
$list2 = new ListNode(2, $list2);
$list2 = new ListNode(1, $list2);

$echoList = (new Solution())->mergeTwoLists($list1, $list2);

while ($echoList) {
echo $echoList->val . PHP_EOL;
$echoList = $echoList->next;
}

Check failure on line 56 in application/console/app.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 blank line at end of file; 2 found

Loading