其他分享
首页 > 其他分享> > 买卖股票的最佳时机含手续费

买卖股票的最佳时机含手续费

作者:互联网

题目链接: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;
    }
};

标签:fee,inHand,int,最佳时机,result,prices,买卖,手续费
来源: https://www.cnblogs.com/ZigHello/p/15010206.html