| Conditions | 7 |
| Paths | 7 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function nextGreaterElement(array $num1, array $num2): array |
||
| 10 | { |
||
| 11 | if (empty($num1) || empty($num2)) { |
||
| 12 | return []; |
||
| 13 | } |
||
| 14 | $ans = $stack = $map = []; |
||
| 15 | foreach ($num2 as $num) { |
||
| 16 | while ($stack && end($stack) < $num) { |
||
|
|
|||
| 17 | $map[array_pop($stack)] = $num; |
||
| 18 | } |
||
| 19 | array_push($stack, $num); |
||
| 20 | } |
||
| 21 | foreach ($num1 as $num) { |
||
| 22 | array_push($ans, $map[$num] ?? -1); |
||
| 23 | } |
||
| 24 | |||
| 25 | return $ans; |
||
| 26 | } |
||
| 28 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.