标签:code for tor lin tco lint ice 代码 amp
class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &prices) {
// write your code here
if(prices.empty())
return 0;
int maxpro=0;
int minprofit=prices[0];
for(int i=1;i<prices.size();i++)
{
if(prices[i]<minprofit)
minprofit=prices[i];
int money=prices[i]-minprofit;
if(money>maxpro)
maxpro=money;
}
return maxpro;
}
};
标签:code for tor lin tco lint ice 代码 amp
原文地址:http://www.cnblogs.com/muziln/p/6517264.html