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

E spiktarenko/hw18 #1141

Open
wants to merge 5 commits into
base: ESpiktarenko/main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions hw18/fraction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

Check failure on line 1 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line

Check failure on line 1 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

End of line character is invalid; expected &quot;\n&quot; but found &quot;\r\n&quot;
// Сложность O(n)
class Solution {

Check failure on line 3 in hw18/fraction.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 3 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace must not be followed by a blank line

Check failure on line 3 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace of a class must be on the line after the definition

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

Check failure on line 10 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

Visibility must be declared on method &quot;fractionToDecimal&quot;

Check failure on line 10 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening brace should be on a new line
$number = $numerator/$denominator;

Check failure on line 11 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space before &quot;/&quot;; 0 found

Check failure on line 11 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space after &quot;/&quot;; 0 found
$str = "".$number;

Check failure on line 12 in hw18/fraction.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space before &quot;.&quot;; 0 found
$dec = explode ('.', $str);
$str_dec = $dec[1];

if ($str_dec==""){
return $str;
}

if(strlen($str_dec)<2){
return $str;
}

$dim=explode($str_dec[strlen($str_dec)-1],$str_dec);

for ($i=(count($dim)-2);$i>=1;$i--){
if($dim[$i]!=$dim[$i-1]){
return $str;
}
}

if($dim[0]==$dim[1]){
return $dec[0].'.('.$dim[0].$str_dec[strlen($str_dec)-1].')';
}else{
return $dec[0].'.'.$dim[0].$str_dec[strlen($str_dec)-1].'('.$dim[1].$str_dec[strlen($str_dec)-1].')';
}
}
}
36 changes: 36 additions & 0 deletions hw18/intersection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Definition for a singly-linked list.
* class ListNode {
* public $val = 0;
* public $next = null;
* function __construct($val) { $this->val = $val; }
* }
* Сложность O(n^2)
*/

class Solution {
/**
* @param ListNode $headA
* @param ListNode $headB
* @return ListNode
*/
function getIntersectionNode($headA, $headB) {
$nodeA = $headA;
$nodeB = $headB;
while (is_null($nodeA)===false)
{
while(is_null($nodeB) === false)
{
if($nodeA===$nodeB)
{
return $nodeA;
}
$nodeB=$nodeB->next;
}
$nodeA = $nodeA->next;
$nodeB = $headB;
}
return null;
}
}
36 changes: 36 additions & 0 deletions hw18/intersection_new.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Definition for a singly-linked list.
* class ListNode {
* public $val = 0;
* public $next = null;
* function __construct($val) { $this->val = $val; }
* }
* Сложность O(n^2)
*/

class Solution {
/**
* @param ListNode $headA
* @param ListNode $headB
* @return ListNode
*/
function getIntersectionNode($headA, $headB) {
$nodeA = $headA;
$nodeB = $headB;
while (is_null($nodeA)===false)
{
while(is_null($nodeB) === false)
{
if($nodeA===$nodeB)
{
return $nodeA;
}
$nodeB=$nodeB->next;
}
$nodeA = $nodeA->next;
$nodeB = $headB;
}
return null;
}
}
Loading