| Conditions | 4 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | public static function numSquares2(int $n): int |
||
| 26 | { |
||
| 27 | if ($n <= 0) { |
||
| 28 | return 0; |
||
| 29 | } |
||
| 30 | $dp = [0]; |
||
| 31 | while (count($dp) <= $n) { |
||
| 32 | $cnt = count($dp); |
||
| 33 | $tmp = PHP_INT_MAX; |
||
| 34 | for ($i = 1; $i * $i <= $cnt; $i++) { |
||
| 35 | $tmp = min($tmp, $dp[$cnt - $i * $i] + 1); |
||
| 36 | } |
||
| 37 | $dp[] = $tmp; |
||
| 38 | } |
||
| 39 | |||
| 40 | return $dp[$n]; |
||
| 41 | } |
||
| 43 |