mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0198.打家劫舍.md
Java code: initialize dp array with length `nums.length` is sufficient
This commit is contained in:
@ -118,7 +118,7 @@ class Solution {
|
|||||||
if (nums == null || nums.length == 0) return 0;
|
if (nums == null || nums.length == 0) return 0;
|
||||||
if (nums.length == 1) return nums[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[0] = nums[0];
|
||||||
dp[1] = Math.max(dp[0], nums[1]);
|
dp[1] = Math.max(dp[0], nums[1]);
|
||||||
for (int i = 2; i < nums.length; i++) {
|
for (int i = 2; i < nums.length; i++) {
|
||||||
|
Reference in New Issue
Block a user