买卖股票的最佳时机 - C++

if(prices.empty())
return 0 ;
int max = 0; /* 定义最大利润 */
int min = prices[0];
for(int i = 1 ; i < prices.size() ; i++ )
{
if(prices[i] < min)
min = prices[i];
int differ = prices[i] - min ;
if(differ > max)
max = differ;
}
return max;

posted @ 2017-03-06 23:31  tong-joker  阅读(452)  评论(0编辑  收藏  举报