2024/12/6 灵茶题单 dp
This commit is contained in:
parent
24e1175d64
commit
24cc5ae131
|
@ -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];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue