class Solution {
public:
    /**
     * 
     * @param prices int整型vector 
     * @return int整型
     */
    /*
    不断更新最小值,不断取得最小值和当前值的gap
    */
    int maxProfit(vector<int>& prices) {
        int len = prices.size();
        if ((len == 0) || (len == 1)) {
            return 0;
        }
        int ret = 0, minPrice = prices[0];
        for (int i = 1; i < len; i++) {
            if (minPrice > prices[i]) {
                minPrice = prices[i];
            }
            ret = max(ret, prices[i] - minPrice);
        }
        return ret;
        // write code here
    }
};