| Conditions | 6 |
| Paths | 5 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function kthSmallest(array $matrix, int $k): int |
||
| 10 | { |
||
| 11 | if (empty($matrix) || $k <= 0) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | $heap = new \SplMaxHeap(); |
||
| 15 | [$m, $n] = [count($matrix), count($matrix[0])]; |
||
| 16 | for ($i = 0; $i < $m; $i++) { |
||
| 17 | for ($j = 0; $j < $n; $j++) { |
||
| 18 | $heap->insert($matrix[$i][$j]); |
||
| 19 | if ($heap->count() > $k) { |
||
| 20 | $heap->extract(); |
||
| 21 | } |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | return $heap->top(); |
||
| 26 | } |
||
| 62 |