买卖股票的最佳时机


class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &price) {

int re = 0;
if(price.size()<2)
return re;
int lowest = price[0];
for(int i=1;i<price.size();i++)
{
int cur = price[i];
re = max(re,cur-lowest);
lowest = min(lowest,cur);
}
return re;
}
};

posted on 2017-03-08 22:00  这位黑洞同学  阅读(102)  评论(0编辑  收藏  举报

导航