Best Time to Buy and Sell Stock

class Solution {
public:
    int maxProfit(vector<int>& prices) {
//eg:     5 6 2 3 1 4;
//        记录i之前最小的元素;

        int min = INT_MAX;
        int pro = 0;
        int n=prices.size();
        for(int i=0;i<n;i++){
            if(prices[i]-min >pro) pro=prices[i]-min;
            else if(prices[i] < min) min = prices[i];
        }
        return pro;
    }
};
原文地址:https://www.cnblogs.com/julie-yang/p/4671485.html