We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents a9c2674 + 29fdafe commit fe9c063Copy full SHA for fe9c063
problems/0714.买卖股票的最佳时机含手续费.md
@@ -199,7 +199,21 @@ class Solution { // 动态规划
199
200
201
Python:
202
-
+```python
203
+class Solution: # 贪心思路
204
+ def maxProfit(self, prices: List[int], fee: int) -> int:
205
+ result = 0
206
+ minPrice = prices[0]
207
+ for i in range(1, len(prices)):
208
+ if prices[i] < minPrice:
209
+ minPrice = prices[i]
210
+ elif prices[i] >= minPrice and prices[i] <= minPrice + fee:
211
+ continue
212
+ else:
213
+ result += prices[i] - minPrice - fee
214
+ minPrice = prices[i] - fee
215
+ return result
216
+```
217
218
Go:
219
0 commit comments