| Conditions | 5 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function nextGreaterElements(array $nums): array |
||
| 10 | { |
||
| 11 | if (empty($nums)) { |
||
| 12 | return []; |
||
| 13 | } |
||
| 14 | $n = count($nums); |
||
| 15 | [$ans, $stack] = [array_fill(0, $n, -1), []]; |
||
| 16 | for ($i = 0; $i < $n * 2; $i++) { |
||
| 17 | $k = $i % $n; |
||
| 18 | while ($stack && $nums[end($stack)] < $nums[$k]) { |
||
|
|
|||
| 19 | $ans[array_pop($stack)] = $nums[$k]; |
||
| 20 | } |
||
| 21 | array_push($stack, $k); |
||
| 22 | } |
||
| 23 | |||
| 24 | return $ans; |
||
| 25 | } |
||
| 53 |
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.