121. Best Time to Buy and Sell Stock

    /*
     * 121. Best Time to Buy and Sell Stock
     * 这道题目虽然简单,但是自己还是做错了。这道题目自己想多了
     * 首先min和max的顺序并无所谓。另外就是可以从0开始循环,不用等到1开始
     */
    public int maxProfit(int[] prices) {
        int min = Integer.MAX_VALUE, max = 0;
        for (int i = 0; i < prices.length; i++) {
            min = Math.min(min, prices[i]);
            max = Math.max(max, prices[i] - min);
        }
        return max;
    }
原文地址:https://www.cnblogs.com/zmyvszk/p/5515878.html