class Solution { public: int maxProfit(vector<int>& prices) { int less=2e5+100; int ans=0; for(int i=0;i<prices.size();i++) { less=min(less,prices[i]);//找出前i个的最小值 ans=max(ans,prices[i]-less);//拿当前的值减去前面最小的值 } return ans; } };