309. Best Time to Buy and Sell Stock with Cooldown Medium
1/**
2 * [309] Best Time to Buy and Sell Stock with Cooldown
3 *
4 * You are given an array prices where prices[i] is the price of a given stock on the i^th day.
5 * Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times) with the following restrictions:
6 *
7 * After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).
8 *
9 * Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
10 *
11 * Example 1:
12 *
13 * Input: prices = [1,2,3,0,2]
14 * Output: 3
15 * Explanation: transactions = [buy, sell, cooldown, buy, sell]
16 *
17 * Example 2:
18 *
19 * Input: prices = [1]
20 * Output: 0
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= prices.length <= 5000
26 * 0 <= prices[i] <= 1000
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/
32// discuss: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn max_profit(prices: Vec<i32>) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_309() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.