| Conditions | 4 |
| Paths | 4 |
| Total Lines | 17 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | } |
||
| 68 |