| Total Complexity | 13 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class FairCandySwap |
||
| 8 | { |
||
| 9 | public static function fairCandySwap(array $a, array $b): array |
||
| 10 | { |
||
| 11 | if (empty($a) || empty($b)) { |
||
| 12 | return []; |
||
| 13 | } |
||
| 14 | [$aSum, $bSum] = [array_sum($a), array_sum($b)]; |
||
| 15 | $dif = (int) (($aSum - $bSum) / 2); |
||
| 16 | for ($i = 0, $m = count($a); $i < $m; $i++) { |
||
| 17 | for ($j = 0, $n = count($b); $j < $n; $j++) { |
||
| 18 | if ($a[$i] - $b[$j] === $dif) { |
||
| 19 | return [$a[$i], $b[$j]]; |
||
| 20 | } |
||
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | return []; |
||
| 25 | } |
||
| 26 | |||
| 27 | public static function fairCandySwap2(array $a, array $b): array |
||
| 45 | } |
||
| 46 | } |
||
| 47 |