题目链接:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/
题目描述:
相关题:买卖股票的最佳时机||
题解:
参考链接:买卖股票的最佳时机含手续费题解
class Solution {
public:
int maxProfit(vector<int>& prices, int fee) {
int result = 0;
int inHand = prices[0];
for(int i = 1; i < prices.size(); i++)
{
if(inHand > prices[i])
inHand = prices[i];
else if(inHand < prices[i] - fee)
{
result += prices[i] - fee - inHand;
inHand = prices[i] - fee;
}
}
return result;
}
};