Skip to content

Commit

Permalink
HW14
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilaki-t committed Mar 10, 2024
1 parent f5c02a7 commit 6ea5328
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

Check failure on line 1 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line
/**
* Definition for a singly-linked list.
* class ListNode {
* public $val = 0;
* public $next = null;
* function __construct($val) { $this->val = $val; }
* }
*/

class Solution

Check failure on line 11 in index.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)
{
/**
* @param ListNode $head
* @return Boolean
*/
function hasCycle($head)

Check failure on line 17 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Visibility must be declared on method &quot;hasCycle&quot;
{
if ($head == null || $head->next == null) {
return false;
}

$slow = $head;
$fast = $head->next;

while ($slow != $fast) {

Check failure on line 26 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Blank line found at start of control structure

if ($fast == null || $fast->next == null) {
return false;
}

$slow = $slow->next;
$fast = $fast->next->next;
}

return true;
}
}


class Solution2

Check failure on line 41 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Each class must be in a file by itself

Check failure on line 41 in index.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 42 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace must not be followed by a blank line

/**
* @param String $digits
* @return String[]
*/
function letterCombinations($digits)

Check failure on line 48 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Visibility must be declared on method &quot;letterCombinations&quot;
{
if (empty($digits)) {
return []; // возвращаем пустой массив для пустой строки ввода
}

$digitMap = [
'2' => ['a', 'b', 'c'],
'3' => ['d', 'e', 'f'],
'4' => ['g', 'h', 'i'],
'5' => ['j', 'k', 'l'],
'6' => ['m', 'n', 'o'],
'7' => ['p', 'q', 'r', 's'],
'8' => ['t', 'u', 'v'],
'9' => ['w', 'x', 'y', 'z'],
];

$result = [];
$currentCombination = '';

$this->generateCombinations($digits, 0, $digitMap, $currentCombination, $result);

return $result;
}

function generateCombinations($digits, $index, $digitMap, $currentCombination, &$result)

Check failure on line 73 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Visibility must be declared on method &quot;generateCombinations&quot;
{
if ($index == strlen($digits)) {
$result[] = $currentCombination;
return;
}

$currentDigit = $digits[$index];
$letters = $digitMap[$currentDigit];

foreach ($letters as $letter) {
$this->generateCombinations($digits, $index + 1, $digitMap, $currentCombination . $letter, $result);
}
}
}

Check failure on line 87 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found

0 comments on commit 6ea5328

Please sign in to comment.