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

hw8 #1204

Open
wants to merge 1 commit into
base: DRepin/hw_1
Choose a base branch
from
Open

hw8 #1204

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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# PHP_2023

https://otus.ru/lessons/razrabotchik-php/?utm_source=github&utm_medium=free&utm_campaign=otus

Сложность o(n), так как прямая зависимость от кол-ва элементов в списках и нужно пройти каждый элемент списка.
85 changes: 34 additions & 51 deletions www/index.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,37 @@
<?php

print 'Redis Check: ';
try {
if (class_exists('Redis')) {
$redis = new Redis();
$redis->connect('redis', 6379);
$info = $redis->info();
print 'Redis version ' . $info['redis_version'] . ' ✓<br>';
} else {
throw new Exception('Class "Redis" not found<br>');
/**
* 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() . ' ✓<br>';
} else {
throw new Exception('Class "Memcache" not found<br>');
}
} 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 . ' ✓<br>';
} else {
throw new Exception('Class "Mysqli" not found<br>');
}
} catch (Exception $e) {
print $e->getMessage();
}

print 'Composer Check: ';
try {
system('composer --version');
print '✓';
} catch (Exception $e) {
print $e->getMessage();
}
}
Loading