Skip to content

Commit 29fdafe

Browse files
authored
Update 0714.买卖股票的最佳时机含手续费.md
Added python version code
1 parent 6bdfab2 commit 29fdafe

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)