날짜별 가격이 적힌 정수형 벡터 prices를 받는다.
한 번 사서 한 번 팔 때, 가장 큰 이득을 구하는 문제
class Solution {
public:
int maxProfit(vector<int>& prices) {
int lower{numeric_limits<int>::max()};
int result{0};
for (auto& price : prices)
{
result = std::max(result, price - lower);
lower = std::min(lower, price);
}
return result;
}
};