Exercises

Best Time to Buy and Sell Stock with Transaction Fee

原题链接

medium

解法:

class Solution {
public:
    int maxProfit(vector<int>& prices, int fee) {
        int maxprofit=0, hold=-prices[0];
        for(int i=1; i<prices.size(); i++){
            maxprofit=max(maxprofit,hold+prices[i]-fee);
            hold=max(hold,maxprofit-prices[i]);
        }
        return maxprofit;
    }
};

Best Time to Buy and Sell Stock with Cooldown

原题链接

medium

解法

最后更新于

这有帮助吗?