This commit is contained in:
programmercarl
2023-09-19 16:21:37 +08:00
parent ab4c44d2a3
commit 631b333c08
9 changed files with 17 additions and 34 deletions

View File

@@ -240,9 +240,9 @@ class Solution {
// 因为马上dp[0]和dp[2]的数据都会变
int temp = dp[0];
int temp1 = dp[2];
dp[0] = Math.max(dp[0], Math.max(dp[3], dp[1]) - prices[i-1]);
dp[0] = Math.max(dp[0], Math.max(dp[3], dp[1]) - prices[i]);
dp[1] = Math.max(dp[1], dp[3]);
dp[2] = temp + prices[i-1];
dp[2] = temp + prices[i];
dp[3] = temp1;
}
return Math.max(dp[3],Math.max(dp[1],dp[2]));