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