| Conditions | 4 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function rob(array $nums): int |
||
| 10 | { |
||
| 11 | $n = count($nums); |
||
| 12 | if ($n <= 0) { |
||
| 13 | return 0; |
||
| 14 | } |
||
| 15 | $dp = array_fill(0, $n + 1, 0); |
||
| 16 | foreach ($nums as $i => $num) { |
||
| 17 | if ($i - 1 < 0) { |
||
| 18 | [$dp[0], $dp[1]] = [0, $num]; |
||
| 19 | } else { |
||
| 20 | $dp[$i + 1] = max($dp[$i], $dp[$i - 1] + $num); |
||
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | return $dp[$n]; |
||
| 25 | } |
||
| 59 |