【leetcode】309. 最佳买卖股票时机含冷冻期

 

#define max(a,b) ((a)>(b))?(a) :(b);
int maxProfit(int* prices, int pricesSize){
    if(pricesSize==0)
        return 0;
    int i, buy=-prices[0], sell=0, pre=0, tmp;
    for (i=1; i<pricesSize; i++){
        tmp=sell;
        sell=max( sell, buy+prices[i] );
        buy=max( buy, pre - prices[i] );
        pre=tmp;        
    }
    return sell;
}

 

posted @ 2021-01-02 16:27  温暖了寂寞  阅读(56)  评论(0编辑  收藏  举报