| Total Complexity | 10 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class HeightChecker |
||
| 8 | { |
||
| 9 | public static function heightChecker(array $heights): int |
||
| 10 | { |
||
| 11 | if (empty($heights)) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | $map = array_fill(0, 101, 0); |
||
| 15 | foreach ($heights as $height) { |
||
| 16 | $map[$height]++; |
||
| 17 | } |
||
| 18 | [$cnt, $curr] = [0, 1]; |
||
| 19 | foreach ($heights as $height) { |
||
| 20 | while ($map[$curr] === 0) { |
||
| 21 | $curr++; |
||
| 22 | } |
||
| 23 | if ($curr !== $height) { |
||
| 24 | $cnt++; |
||
| 25 | } |
||
| 26 | $map[$curr]--; |
||
| 27 | } |
||
| 28 | |||
| 29 | return $cnt; |
||
| 30 | } |
||
| 31 | |||
| 32 | public static function heightChecker2(array $heights): int |
||
| 47 | } |
||
| 48 | } |
||
| 49 |