关于股票最佳买卖时机的lintcode代码
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;
}
};