买卖股票的最佳时机

时间:2017-03-08 22:59:21   收藏:0   阅读:255


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

原文:http://www.cnblogs.com/aly15109725486/p/6523296.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!