class Solution {
public:
int maxProfit(vector<int>& prices) {
int ans = 0;
int mn = INT_MAX / 2;
for (auto &x: prices) {
ans = max(ans, x - mn);
mn = min(mn, x);
}
return ans;
}
};
Time Complexity: O(n)
Space: O(1)
挺無聊的