121. Best Time to Buy and Sell Stock
class Solution { public: int maxProfit(vector<int>& prices) { int res = 0; int low = INT_MAX; for (auto i : prices) { if (i < low) low = i; if (i - low > res) res = i - low; } return res; } };
class Solution { public: int maxProfit(vector<int>& prices) { int res = 0; int low = INT_MAX; for (auto i : prices) { if (i < low) low = i; if (i - low > res) res = i - low; } return res; } };