| Conditions | 8 |
| Paths | 11 |
| Total Lines | 29 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 31 | public static function findMissingRanges2(array &$nums, int $lower, int $upper): array |
||
| 32 | { |
||
| 33 | $ans = []; |
||
| 34 | if (empty($nums)) { |
||
| 35 | return $ans; |
||
| 36 | } |
||
| 37 | $next = $lower; |
||
| 38 | foreach ($nums as $num) { |
||
| 39 | if ($lower === PHP_INT_MAX) { |
||
| 40 | return $ans; |
||
| 41 | } |
||
| 42 | if ($num < $next) { |
||
| 43 | continue; |
||
| 44 | } |
||
| 45 | if ($num === $next) { |
||
| 46 | $next++; |
||
| 47 | continue; |
||
| 48 | } |
||
| 49 | $ans[] = self::getRange($next, $num - 1); |
||
| 50 | if ($num === PHP_INT_MAX) { |
||
| 51 | return $ans; |
||
| 52 | } |
||
| 53 | $next = $num + 1; |
||
| 54 | } |
||
| 55 | if ($next <= $upper) { |
||
| 56 | $ans[] = self::getRange($next, $upper); |
||
| 57 | } |
||
| 58 | |||
| 59 | return $ans; |
||
| 60 | } |
||
| 67 |