| Total Complexity | 14 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class CountingBits |
||
| 8 | { |
||
| 9 | public static function countBits(int $num): array |
||
| 20 | } |
||
| 21 | |||
| 22 | public static function countBits2(int $num): array |
||
| 34 | } |
||
| 35 | |||
| 36 | public static function countBits3(int $num): array |
||
| 37 | { |
||
| 38 | if ($num <= 0) { |
||
| 39 | return []; |
||
| 40 | } |
||
| 41 | $bits = array_fill(0, $num + 1, 0); |
||
| 42 | $bits[0] = 0; |
||
| 43 | $pow = 1; |
||
| 44 | for ($i = 1, $t = 0; $i <= $num; $i++, $t++) { |
||
| 45 | if ($i === $pow) { |
||
| 46 | $pow *= 2; |
||
| 47 | $t = 0; |
||
| 48 | } |
||
| 49 | $bits[$i] = $bits[$t] + 1; |
||
| 50 | } |
||
| 51 | |||
| 52 | return $bits; |
||
| 53 | } |
||
| 54 | |||
| 55 | public static function countBits4(int $num): array |
||
| 66 | } |
||
| 67 | } |
||
| 68 |