标签:price tor size min ice turn i++ for ram
class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &prices) {
// write your code here
int ret = 0;
if(prices.size()<2)
return ret;
int lowest = prices[0];
for(int i=1;i<prices.size();i++)
{
int cur = prices[i];
ret = max(ret,cur-lowest);
lowest = min(lowest,cur);
}
return ret;
}
};
标签:price tor size min ice turn i++ for ram
原文地址:http://www.cnblogs.com/w1500802028/p/6525778.html