LeetCode 714 - Best Time to Buy and Sell Stock with Transaction Fee
Difficulty: medium
Stock Series:
Part 1: LeetCode 121 - Best Time to Buy and Sell Stock
Part 2: LeetCode 122 - Best Time to Buy and Sell Stock II
Part 3: LeetCode 123 - Best Time to Buy and Sell Stock III
Part 4: LeetCode 188 - Best Time to Buy and Sell Stock IV
Part 5: LeetCode 309 - Best Time to Buy and Sell Stock with Cooldown
Part 6: LeetCode 714 - Best Time to Buy and Sell Stock with Transaction Fee
Problem Description
English (Best Time to Buy and Sell Stock with Transaction Fee)
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.
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.
Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
Example 1:
1 |
|
Example 2:
1 |
|
Constraints:
1 <= prices.length <= 5 * 10^4
1 <= prices[i] < 5 * 10^4
0 <= fee < 5 * 10^4
Chinese (买卖股票的最佳时机含手续费)
给定一个整数数组 prices
,其中 prices[i]
表示第 i
天的股票价格 ;整数 fee
代表了交易股票的手续费用。
你可以无限次地完成交易,但是你每笔交易都需要付手续费。如果你已经购买了一个股票,在卖出它之前你就不能再继续购买股票了。
返回获得利润的最大值。
注意: 这里的一笔交易指买入持有并卖出股票的整个过程,每笔交易你只需要为支付一次手续费。
示例 1:
1 |
|
示例 2:
1 |
|
提示:
1 <= prices.length <= 5 * 10^4
1 <= prices[i] < 5 * 10^4
0 <= fee < 5 * 10^4
Solution
C++
1 |
|