package leetcode;

/**
 * https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/
 */
public class Problem309 {
    public int maxProfit(int[] prices) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem309 prob = new Problem309();
        System.out.println(prob.maxProfit(new int[]{1, 2, 3, 0, 2})); // 3
        System.out.println(prob.maxProfit(new int[]{1, 2, 3, 0, 2, 4})); // 5
        System.out.println(prob.maxProfit(new int[]{3, 2, 1})); // 0
        System.out.println(prob.maxProfit(new int[]{1, 2, 3})); // 2
        System.out.println(prob.maxProfit(new int[]{3, 0, 0, 0, 5})); // 5
    }
}

@@ -179,495 +179,646 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem309 prob = new Problem309();%0A        System.out.println(prob.maxProfit(new int%5B%5D%7B1, 2, 3, 0, 2%7D)); // 3%0A        System.out.println(prob.maxProfit(new int%5B%5D%7B1, 2, 3, 0, 2, 4%7D)); // 5%0A        System.out.println(prob.maxProfit(new int%5B%5D%7B3, 2, 1%7D)); // 0%0A        System.out.println(prob.maxProfit(new int%5B%5D%7B1, 2, 3%7D)); // 2%0A        System.out.println(prob.maxProfit(new int%5B%5D%7B3, 0, 0, 0, 5%7D)); // 5
+if (prices.length %3C= 1) %7B%0A            return 0;%0A        %7D%0A        int%5B%5D states1 = new int%5Bprices.length%5D;%0A        int%5B%5D states2 = new int%5Bprices.length%5D;%0A        int%5B%5D states3 = new int%5Bprices.length%5D;%0A        states1%5B0%5D = 0;%0A        states2%5B0%5D = -prices%5B0%5D;%0A        states3%5B0%5D = Integer.MIN_VALUE;%0A        for (int i = 1; i %3C prices.length; i++) %7B%0A            states1%5Bi%5D = Math.max(states1%5Bi - 1%5D, states3%5Bi - 1%5D);%0A            states2%5Bi%5D = Math.max(states2%5Bi - 1%5D, states1%5Bi - 1%5D - prices%5Bi%5D);%0A            states3%5Bi%5D = states2%5Bi - 1%5D + prices%5Bi%5D;%0A        %7D%0A        return Math.max(states1%5Bprices.length - 1%5D, states3%5Bprices.length - 1%5D);
 %0A   

Solve problem 309