| Conditions | 4 |
| Paths | 4 |
| Total Lines | 14 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function numSquares(int $n): int |
||
| 10 | { |
||
| 11 | if ($n <= 0) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | $dp = array_fill(0, $n + 1, PHP_INT_MAX); |
||
| 15 | $dp[0] = 0; |
||
| 16 | for ($i = 1; $i <= $n; $i++) { |
||
| 17 | for ($j = 1; $j * $j <= $i; $j++) { |
||
| 18 | $dp[$i] = min($dp[$i], $dp[$i - $j * $j] + 1); |
||
| 19 | } |
||
| 20 | } |
||
| 21 | |||
| 22 | return array_pop($dp); |
||
| 23 | } |
||
| 43 |