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