package leetcode;

/**
 * https://leetcode.com/problems/min-cost-climbing-stairs/
 */
public class Problem746 {
    public int minCostClimbingStairs(int[] cost) {
        int[] dp = new int[cost.length];
        int min = 0;
        for (int i = cost.length - 1; i >= 0; i--) {
            int a = 0;
            if (i - 2 >= 0) {
                a = dp[i - 2];
            }
            int b = dp[i - 1];
            dp[i] = cost[i] + Math.min(a, b);
        }
        return min;
    }

    public static void main(String[] args) {
        Problem746 prob = new Problem746();
        System.out.println(prob.minCostClimbingStairs(new int[]{10, 15, 20})); // 15
        System.out.println(prob.minCostClimbingStairs(new int[]{1, 100, 1, 1, 1, 100, 1, 1, 100, 1})); // 6
    }
}

@@ -198,30 +198,13 @@
 ngth
-%5D;%0A        int min = 0
+ + 2%5D
 ;%0A  
@@ -270,17 +270,56 @@
     
-int a = 0
+dp%5Bi%5D = Math.min(dp%5Bi + 1%5D, dp%5Bi + 2%5D) + cost%5Bi%5D
 ;%0A  
@@ -328,69 +328,172 @@
     
+%7D%0A
     
-if (i - 2 %3E= 0) %7B%0A                a = dp%5Bi - 2
+    return Math.min(dp%5B0%5D, dp%5B1%5D);%0A    %7D%0A%0A//    public int minCostClimbingStairs(int%5B%5D cost) %7B%0A//        Integer%5B%5D memo = new Integer%5Bcost.length
 %5D;%0A
+//
         
     
@@ -492,181 +492,315 @@
     
-    %7D%0A            int b = dp%5Bi - 1%5D;%0A            dp%5Bi%5D = cost%5Bi%5D + Math.min(a, b);%0A        %7D%0A        return min;%0A    %7D%0A%0A    public static void main(String%5B%5D args
+return Math.min(minCostClimbingStairs(cost, 0, memo), minCostClimbingStairs(cost, 1, memo));%0A//    %7D%0A//%0A//    private static int minCostClimbingStairs(int%5B%5D cost, int idx, Integer%5B%5D memo) %7B%0A//        if (idx %3E= cost.length) %7B%0A//            return 0;%0A//        %7D%0A//        if (memo%5Bidx%5D != null
 ) %7B%0A
+//
         
 Prob
@@ -799,76 +799,60 @@
     
-Problem746 prob = new Problem746();%0A        System.out.println(prob.
+    return memo%5Bidx%5D;%0A//        %7D%0A//        int a = 
 minC
@@ -873,147 +873,191 @@
 irs(
-new int%5B%5D%7B10,
+cost, idx +
  1
-5
 , 
-20%7D)); 
+memo);%0A
 // 
-15%0A
        
- System.out.println(prob.minCostClimbingStairs(new int%5B%5D%7B1, 100, 1, 1, 1, 100, 1, 1, 100, 1%7D)); // 6%0A
+int b = minCostClimbingStairs(cost, idx + 2, memo);%0A//        int min = Math.min(a, b) + cost%5Bidx%5D;%0A//        memo%5Bidx%5D = min;%0A//        return min;%0A//
     

Solve problem 746