Update 0198.打家劫舍.md
Java code: initialize dp array with length `nums.length` is sufficient
This commit is contained in:
parent
e470235464
commit
33dcb8dbd3
|
|
@ -118,7 +118,7 @@ class Solution {
|
|||
if (nums == null || nums.length == 0) return 0;
|
||||
if (nums.length == 1) return nums[0];
|
||||
|
||||
int[] dp = new int[nums.length + 1];
|
||||
int[] dp = new int[nums.length];
|
||||
dp[0] = nums[0];
|
||||
dp[1] = Math.max(dp[0], nums[1]);
|
||||
for (int i = 2; i < nums.length; i++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue