码迷,mamicode.com
首页 > 其他好文 > 详细

买卖股票的最佳时机

时间:2017-07-25 19:43:25      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:截图   maximum   lin   img   fit   image   images   技术分享   -128   

代码:

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;

}

};

lintcode截图:

技术分享

 

买卖股票的最佳时机

标签:截图   maximum   lin   img   fit   image   images   技术分享   -128   

原文地址:http://www.cnblogs.com/aly15109725486/p/7235695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!