Update 0123.买卖股票的最佳时机III.md

This commit is contained in:
fwqaaq
2023-06-30 10:31:32 +08:00
committed by GitHub
parent c1b2141ea2
commit 85daaae465

View File

@ -442,6 +442,24 @@ impl Solution {
}
```
> 版本二(绕)
```rust
impl Solution {
pub fn max_profit(prices: Vec<i32>) -> i32 {
let mut dp = vec![0, -prices[0], 0, -prices[0], 0];
for p in prices {
dp[1] = dp[1].max(-p);
dp[2] = dp[2].max(dp[1] + p);
dp[3] = dp[3].max(dp[2] - p);
dp[4] = dp[4].max(dp[3] + p);
}
dp[4]
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">