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

Added python version code
This commit is contained in:
LiangDazhu
2021-05-22 23:01:54 +08:00
committed by GitHub
parent 6bdfab2883
commit 29fdafecc4

View File

@ -199,7 +199,21 @@ class Solution { // 动态规划
Python
```python
class Solution: # 贪心思路
def maxProfit(self, prices: List[int], fee: int) -> int:
result = 0
minPrice = prices[0]
for i in range(1, len(prices)):
if prices[i] < minPrice:
minPrice = prices[i]
elif prices[i] >= minPrice and prices[i] <= minPrice + fee:
continue
else:
result += prices[i] - minPrice - fee
minPrice = prices[i] - fee
return result
```
Go