From e9f7683d4679a6126907134ba4c623267b1ba951 Mon Sep 17 00:00:00 2001 From: LiHua <1985390347@qq.com> Date: Wed, 24 Nov 2021 10:11:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E4=BA=86188=E4=B8=80?= =?UTF-8?q?=E7=BB=B4=E6=95=B0=E7=BB=84java=E8=A7=A3=E9=A2=98=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0188.买卖股票的最佳时机IV.md | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/problems/0188.买卖股票的最佳时机IV.md b/problems/0188.买卖股票的最佳时机IV.md index 73861b35..0e898b43 100644 --- a/problems/0188.买卖股票的最佳时机IV.md +++ b/problems/0188.买卖股票的最佳时机IV.md @@ -222,19 +222,32 @@ class Solution { //版本三:一维 dp数组 class Solution { public int maxProfit(int k, int[] prices) { - //在版本二的基础上,由于我们只关心前一天的股票买入情况,所以只存储前一天的股票买入情况 - if(prices.length==0)return 0; - int[] dp=new int[2*k+1]; - for (int i = 1; i <2*k ; i+=2) { - dp[i]=-prices[0]; + if(prices.length == 0){ + return 0; } - for (int i = 0; i