parent
6bdfab2883
commit
29fdafecc4
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue