| Conditions | 5 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 29 | public static function dailyTemperatures2(array $nums): array |
||
| 30 | { |
||
| 31 | if (empty($nums)) { |
||
| 32 | return []; |
||
| 33 | } |
||
| 34 | $n = count($nums); |
||
| 35 | [$ans, $stack] = [array_fill(0, $n, 0), []]; |
||
| 36 | for ($i = 0; $i < $n; $i++) { |
||
| 37 | while ($stack && $nums[end($stack)] < $nums[$i]) { |
||
|
|
|||
| 38 | $k = array_pop($stack); |
||
| 39 | $ans[$k] = $i - $k; |
||
| 40 | } |
||
| 41 | array_push($stack, $i); |
||
| 42 | } |
||
| 43 | |||
| 44 | return $ans; |
||
| 45 | } |
||
| 47 |
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.