Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 14 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jul 20, 2023
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
7d92df3
Update 0309.最佳买卖股票时机含冷冻期.md about rust
fwqaaq Jun 30, 2023
fc2a54a
Merge pull request #2160 from fwqaaq/patch-41
youngyangyang04 Jul 20, 2023
c3ebc91
更新 双指针总结 排版格式修复
jinbudaily Jul 20, 2023
de770c6
更新 栈与队列理论基础 排版格式修复
jinbudaily Jul 20, 2023
4b5e198
更新 0232.用栈实现队列 排版格式修复
jinbudaily Jul 20, 2023
c18dbf0
更新 0225.用队列实现栈 排版格式修复
jinbudaily Jul 20, 2023
a1ef2d0
更新 020.有效的括号 排版格式修复
jinbudaily Jul 20, 2023
70888c2
更新 1047.删除字符串中的所有相邻重复项 排版格式修复
jinbudaily Jul 20, 2023
7f4d740
更新 0150.逆波兰表达式求值 排版格式修复
jinbudaily Jul 20, 2023
5a6bf6d
更新 0239.滑动窗口最大值 排版格式修复
jinbudaily Jul 20, 2023
0e4f91d
更新 0347.前k个高频元素 排版格式修复
jinbudaily Jul 20, 2023
f7b87e6
更新 栈与队列总结 排版格式修复
jinbudaily Jul 20, 2023
5d76e86
Merge branch 'master' of github.com:jinbudaily/leetcode-master
jinbudaily Jul 20, 2023
e6b208a
Merge pull request #2194 from jinbudaily/master
youngyangyang04 Jul 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion problems/0309.最佳买卖股票时机含冷冻期.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,29 @@ function maxProfit(prices: number[]): number {
};
```


Rust:

```rust
impl Solution {
pub fn max_profit(prices: Vec<i32>) -> i32 {
/*
* dp[i][0]: 持股状态;
* dp[i][1]: 无股状态,当天为非冷冻期;
* dp[i][2]: 无股状态,当天卖出;
* dp[i][3]: 无股状态,当天为冷冻期;
*/
let mut dp = vec![vec![0; 4]; prices.len()];
dp[0][0] = -prices[0];
for (i, &p) in prices.iter().enumerate().skip(1) {
dp[i][0] = dp[i - 1][0].max((dp[i - 1][3] - p).max(dp[i - 1][1] - p));
dp[i][1] = dp[i - 1][1].max(dp[i - 1][3]);
dp[i][2] = dp[i - 1][0] + p;
dp[i][3] = dp[i - 1][2];
}
*dp[prices.len() - 1].iter().skip(1).max().unwrap()
}
}
```


<p align="center">
Expand Down

AltStyle によって変換されたページ (->オリジナル) /