mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
feat: 動態規劃leetcode#714,新增python解法
This commit is contained in:
@ -188,6 +188,20 @@ class Solution:
|
||||
return max(dp[-1][0], dp[-1][1])
|
||||
```
|
||||
|
||||
```python
|
||||
class Solution:
|
||||
def maxProfit(self, prices: List[int], fee: int) -> int:
|
||||
# 持有股票手上的最大現金
|
||||
hold = -prices[0] - fee
|
||||
# 不持有股票手上的最大現金
|
||||
not_hold = 0
|
||||
for price in prices[1:]:
|
||||
new_hold = max(hold, not_hold - price - fee)
|
||||
new_not_hold = max(not_hold, hold + price)
|
||||
hold, not_hold = new_hold, new_not_hold
|
||||
return not_hold
|
||||
```
|
||||
|
||||
### Go:
|
||||
|
||||
```go
|
||||
|
Reference in New Issue
Block a user