标签:tor i++ return fit 股票 size i+1 ice amp
class Solution {
public:
int maxProfit(vector<int> &prices)
{
if(prices.size() == 0)
return 0;
int min=prices[0],max=0,sum=prices.size();
for(int i=0;i<sum-1;i++)
{
if(prices[i+1]<min)
{
min=prices[i+1];
}
else
{
if(max<prices[i+1]-min)
max=prices[i+1]-min;
}
}
return max;
}
};
标签:tor i++ return fit 股票 size i+1 ice amp
原文地址:http://www.cnblogs.com/lfx456/p/6522164.html