2024/12/6 灵茶题单 dp

This commit is contained in:
Cool 2024-12-06 17:42:16 +08:00
parent 24e1175d64
commit 24cc5ae131
1 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package com.cool.ling_cha_mount.dp;
public class Num198 {
public int rob(int[] nums) {
int[] dp = new int[nums.length + 2];
for (int i = 0; i < nums.length; i++) {
dp[i + 2] = Math.max(dp[i] + nums[i], dp[i + 1]);
}
return dp[nums.length + 1];
}
}