mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Update 0714.买卖股票的最佳时机含手续费.md
Added python version code
This commit is contained in:
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user