Skip to content

Latest commit

 

History

History
14 lines (13 loc) · 319 Bytes

121. Best Time to Buy and Sell Stock.md

File metadata and controls

14 lines (13 loc) · 319 Bytes
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int maxPro = 0, minPrice = INT_MAX;
        for (int i = 0; i < prices.size(); ++i) {
            minPrice = min(prices[i], minPrice);
            maxPro = max(maxPro, prices[i] - minPrice);
        }
        return maxPro;
    }
};