class Solution {
public:
int maxProfit(vector<int>& prices) {
int answer = 0;
int maxPrice = prices.back();
for(int i = prices.size() - 2; i>=0; i--) {
maxPrice = max(prices[i], maxPrice);
answer = max(answer, maxPrice - prices[i]);
}
return answer;
}
};
댓글 0