public int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0 || prices.length == 1) return 0;
        int[] sells = new int[prices.length];
        int[] buys = new int[prices.length];
        sells[0] = 0;
        sells[1] = Math.max(0, prices[1] - prices[0]);
        buys[0] = -prices[0];
        buys[1] = Math.max(-prices[0], -prices[1]);
        for (int i = 2; i < prices.length; ++i) {
            sells[i] = Math.max(sells[i - 1], buys[i - 1] + prices[i]);
            buys[i] = Math.max(buys[i - 1], sells[i - 2] - prices[i]);
        }
        return sells[prices.length - 1];
    }