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

Add to List 121. Best Time to Buy and Sell Stock

时间:2017-11-12 17:32:33      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:amp   ++   vector   and   end   turn   auto   size   price   

class Solution {
public:
int maxProfit(vector<int>& prices) {
int maxCur = 0, maxAll = 0;
if(prices.size() <= 1) return 0;
auto i = prices.begin();
++i;
for(; i != prices.end(); ++i) {
maxCur = max(0, maxCur += *i - *(--i));
maxAll = max(maxCur, maxAll);
++i;
}
return maxAll;
}
};

Add to List 121. Best Time to Buy and Sell Stock

标签:amp   ++   vector   and   end   turn   auto   size   price   

原文地址:http://www.cnblogs.com/bloomingFlower/p/7821925.html

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