【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;
}

 

上一篇:Assertion failed: new_time >= loop->time, file c:\ws\deps\uv\src\win\core.c, line 309


下一篇:309, 二叉搜索树中第K小的元素