class Solution {
public:
int maxProfit(vector<int>& prices) {
int buy=prices[0],n=prices.size(),res=0;//记录最小值
for(int i=1;i<n;i++)//枚举第几天卖出
{
res=max(res,prices[i]-buy);
buy=min(buy,prices[i]);
}
return res;
}
};
标签:买卖,int,121,vector,最佳时机,prices
From: https://www.cnblogs.com/tangxibomb/p/17385166.html