public int maxProfit2(int[] prices) {
        if (prices == null || prices.length == 0 || prices.length == 1) return 0;
        int[] sells = new int[3];
        int[] buys = new int[2];
        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 % 3] = Math.max(sells[(i - 1) % 3], buys[(i - 1) % 2] + prices[i]);
            buys[i % 2] = Math.max(buys[(i - 1) % 2], sells[(i - 2) % 3] - prices[i]);
        }
        return sells[(prices.length - 1) % 3];
    }