RuslanHeorhiiev

Solution 1.1.2

Jun 18th, 2020
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. /**
  2.  * Класс линейной реализации
  3.  */
  4. class Solution {
  5.  
  6.      /**
  7.      * Возвращает ключи суммы
  8.      *
  9.      * @param Integer[] $nums
  10.      * @param Integer $target
  11.      * @return Integer[]
  12.      */
  13.     public static function twoSum(array $nums,  int $target) {                  
  14.         $c = count($nums);
  15.        
  16.         for ($i = 0; $i < $c; $i++) {            
  17.             for ($y = $i + 1; $y < $c; $y++) {
  18.                 if ($nums[$i] + $nums[$y] == $target) {
  19.                     return [$i, $y];
  20.                 }                
  21.             }          
  22.         }    
  23.        
  24.         return [];            
  25.     }        
  26. }
Advertisement
Add Comment
Please, Sign In to add comment