From 051459a5426fc6ad44e069bbd7ab22b3f5d737b8 Mon Sep 17 00:00:00 2001 From: suinming <0223314338aa@gmail.com> Date: Tue, 27 Aug 2024 10:45:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8B=95=E6=85=8B=E8=A6=8F=E5=8A=83lee?= =?UTF-8?q?tcode#714=EF=BC=8C=E6=96=B0=E5=A2=9Epython=E8=A7=A3=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...š„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md b/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md index 73714147..b0e8b141 100644 --- a/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md +++ b/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md @@ -188,6 +188,20 @@ class Solution: return max(dp[-1][0], dp[-1][1]) ``` +```python +class Solution: + def maxProfit(self, prices: List[int], fee: int) -> int: + # æŒæœ‰è‚¡ç¥¨æ‰‹ä¸Šçš„æœ€å¤§ç¾é‡‘ + hold = -prices[0] - fee + # 䏿Œæœ‰è‚¡ç¥¨æ‰‹ä¸Šçš„æœ€å¤§ç¾é‡‘ + not_hold = 0 + for price in prices[1:]: + new_hold = max(hold, not_hold - price - fee) + new_not_hold = max(not_hold, hold + price) + hold, not_hold = new_hold, new_not_hold + return not_hold +``` + ### Go: ```go