Conditions | 7 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
29 | public static function intersect2(array $p, array $q): array |
||
30 | { |
||
31 | if (empty($p) || empty($q)) { |
||
32 | return []; |
||
33 | } |
||
34 | sort($p); |
||
35 | sort($q); |
||
36 | [$ans, $m, $n] = [[], count($p), count($q)]; |
||
37 | $i = $j = 0; |
||
38 | while ($i < $m && $j < $n) { |
||
39 | if ($p[$i] > $q[$j]) { |
||
40 | $j++; |
||
41 | } elseif ($p[$i] < $q[$j]) { |
||
42 | $i++; |
||
43 | } else { |
||
44 | array_push($ans, $p[$i]); |
||
45 | $i++; |
||
46 | $j++; |
||
47 | } |
||
48 | } |
||
49 | |||
50 | return $ans; |
||
51 | } |
||
53 |