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

HW18 #1152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

HW18 #1152

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
80 changes: 80 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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


class Solution

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

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace must not be followed by a blank line

/**
* @param Integer $numerator
* @param Integer $denominator
* @return String
*/
function fractionToDecimal($numerator, $denominator)

Check failure on line 12 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Visibility must be declared on method &quot;fractionToDecimal&quot;
{
if ($numerator == 0) {
return "0";
}

$result = '';

if (($numerator < 0) ^ ($denominator < 0)) {
$result .= '-';
}

$numerator = abs($numerator);
$denominator = abs($denominator);
$result .= (string)(int)($numerator / $denominator);

$remainder = $numerator % $denominator;
if ($remainder == 0) {
return $result;
}

$result .= '.';

$fractionalPart = [];
$map = [];

while ($remainder != 0) {
if (isset($map[$remainder])) {
$startIndex = $map[$remainder];
$nonRepeatingPart = implode('', array_slice($fractionalPart, 0, $startIndex));
$repeatingPart = implode('', array_slice($fractionalPart, $startIndex));
return $result . $nonRepeatingPart . '(' . $repeatingPart . ')';
}

$map[$remainder] = count($fractionalPart);
$remainder *= 10;
$fractionalPart[] = (string)(int)($remainder / $denominator);
$remainder %= $denominator;
}

return $result . implode('', $fractionalPart);
}
}


class Solution2

Check failure on line 57 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 57 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 $headA
* @param ListNode $headB
* @return ListNode
*/
function getIntersectionNode($headA, $headB)

Check failure on line 64 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Visibility must be declared on method &quot;getIntersectionNode&quot;
{
$pointerA = $headA;
$pointerB = $headB;

while ($pointerA !== $pointerB) {
$pointerA = $pointerA ? $pointerA->next : $headB;
$pointerB = $pointerB ? $pointerB->next : $headA;

if ($pointerA === $pointerB) {
return $pointerA;
}
}

return $pointerA;
}
}

Check failure on line 80 in index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 newline at end of file; 0 found
Loading