class Solution:
def maxProfit(self, prices: List[int]) -> int:
cost,profit = float("+inf"),0
for price in prices:
cost = min(price,cost)
profit = max(profit,price - cost)
return profit
class Solution {
public:
int maxProfit(vector<int>& prices) {
int cost = 1e9;
int profit = 0;
for(int i = 0;i < prices.size();i++){
cost = min(cost,prices[i]);
profit = max(profit,prices[i]-cost);
}
return profit;
}
};