| Conditions | 6 |
| Paths | 5 |
| Total Lines | 23 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 37 | public static function nthUglyNumber2(int $n): int |
||
| 38 | { |
||
| 39 | if ($n <= 0) { |
||
| 40 | return 0; |
||
| 41 | } |
||
| 42 | if ($n === 1) { |
||
| 43 | return 1; |
||
| 44 | } |
||
| 45 | $heap = new \SplMinHeap(); |
||
| 46 | $heap->insert(1); |
||
| 47 | for ($i = 1; $i < $n; $i++) { |
||
| 48 | $value = $heap->top(); |
||
| 49 | $heap->extract(); |
||
| 50 | while (!$heap->isEmpty() && $heap->top() === $value) { |
||
| 51 | $value = $heap->top(); |
||
| 52 | $heap->extract(); |
||
| 53 | } |
||
| 54 | $heap->insert($value * 2); |
||
| 55 | $heap->insert($value * 3); |
||
| 56 | $heap->insert($value * 5); |
||
| 57 | } |
||
| 58 | |||
| 59 | return $heap->top(); |
||
| 60 | } |
||
| 62 |