class Solution {
public:
/**
*
* @param prices int整型vector
* @return int整型
*/
int maxProfit(vector<int>& prices) {
int mn = prices[0];
int ans = 0;
for(int i=1; i<prices.size(); i++){
if(prices[i] < mn){
mn = prices[i];
} else {
ans = max(ans, prices[i] - mn);
}
}
return ans;
// write code here
}
};

京公网安备 11010502036488号