From 5c5958b77866a74dfc16d69bc784873e66e09e2d Mon Sep 17 00:00:00 2001 From: Dmitriy Repin Date: Tue, 16 Apr 2024 00:55:56 +0300 Subject: [PATCH] hw8 --- README.md | 2 ++ www/index.php | 85 +++++++++++++++++++++------------------------------ 2 files changed, 36 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index e16b2a49b..075767386 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # PHP_2023 https://otus.ru/lessons/razrabotchik-php/?utm_source=github&utm_medium=free&utm_campaign=otus + +Сложность o(n), так как прямая зависимость от кол-ва элементов в списках и нужно пройти каждый элемент списка. \ No newline at end of file diff --git a/www/index.php b/www/index.php index 06489a7d6..4042e9f65 100644 --- a/www/index.php +++ b/www/index.php @@ -1,54 +1,37 @@ connect('redis', 6379); - $info = $redis->info(); - print 'Redis version ' . $info['redis_version'] . ' ✓
'; - } else { - throw new Exception('Class "Redis" not found
'); +/** + * Definition for a singly-linked list. + * class ListNode { + * public $val = 0; + * public $next = null; + * function __construct($val = 0, $next = null) { + * $this->val = $val; + * $this->next = $next; + * } + * } + */ +class Solution +{ + /** + * @param ListNode $list1 + * @param ListNode $list2 + * @return ListNode + */ + function mergeTwoLists($list1, $list2) + { + $tmp = null; + if ($list1 == null) { + $tmp = $list2; + } elseif ($list2 == null) { + $tmp = $list1; + } elseif ($list1->val < $list2->val) { + $list1->next = $this->mergeTwoLists($list1->next, $list2); + $tmp = $list1; + } elseif ($list1->val >= $list2->val) { + $list2->next = $this->mergeTwoLists($list2->next, $list1); + $tmp = $list2; + } + return $tmp; } -} catch (Exception $e) { - print $e->getMessage(); -} - -print 'Memcache Check: '; -try { - if (class_exists('Memcache')) { - $memcache = new Memcache(); - $memcache->connect('memcached', 11211); - print 'Memcache version ' . $memcache->getVersion() . ' ✓
'; - } else { - throw new Exception('Class "Memcache" not found
'); - } -} catch (Exception $e) { - print $e->getMessage(); -} - -print 'Mysql Check: '; -try { - if (class_exists('Mysqli')) { - $mysqli = new Mysqli( - 'mysql', - 'singurix', - 'VQu44)wBLQ', - 'singurixDB', - 3306 - ); - print 'Mysql version ' . $mysqli->server_info . ' ✓
'; - } else { - throw new Exception('Class "Mysqli" not found
'); - } -} catch (Exception $e) { - print $e->getMessage(); -} - -print 'Composer Check: '; -try { - system('composer --version'); - print '✓'; -} catch (Exception $e) { - print $e->getMessage(); -} +} \ No newline at end of file