标签: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