Skip to content

Commit fe9c063

Browse files
Merge pull request #230 from LiangDazhu/patch-16
Update 0714.买卖股票的最佳时机含手续费.md
2 parents a9c2674 + 29fdafe commit fe9c063

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

problems/0714.买卖股票的最佳时机含手续费.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,21 @@ class Solution { // 动态规划
199199

200200

201201
Python:
202-
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+
```
203217

204218
Go:
205219

0 commit comments

Comments
 (0)