class Solution {
public:
int maxProfit(vector<int>& prices) {
int cost = 1e9,profit = 0;
for(int price:prices)
{
cost = min(cost,price);
profit = max(profit,price-cost);
}
return profit;
}
};
暴力循环会超时