diff --git a/hw18/fraction.php b/hw18/fraction.php new file mode 100644 index 000000000..d77b530f3 --- /dev/null +++ b/hw18/fraction.php @@ -0,0 +1,38 @@ +=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].')'; + } + } +} diff --git a/hw18/intersection.php b/hw18/intersection.php new file mode 100644 index 000000000..48f81743f --- /dev/null +++ b/hw18/intersection.php @@ -0,0 +1,36 @@ +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; + } +} diff --git a/hw18/intersection_new.php b/hw18/intersection_new.php new file mode 100644 index 000000000..48f81743f --- /dev/null +++ b/hw18/intersection_new.php @@ -0,0 +1,36 @@ +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; + } +}