class Solution {
public:
int maxProfit(vector<int> &prices) {
//找到价格最低和最高的一天,最低的一天要在最高一天之前,采用贪心算法,每一次找到最大的利润,同时找到最小的买入价格
int count=prices.size();
if(count<2)
return 0;
int profit=0;
int low=prices[0];
int i;
for(i=1;i<count;i++)
{
profit=max(profit,prices[i]-low);
low=min(low,prices[i]);
}
return profit;
}
};