Blue Bridge Cup Day 8

Topic 1

code:

package day8;

public class day8_test1 {
    public int minCostClimbingStairs(int[] cost) {
        int[] d = new int[cost.length + 1];
        int i = 0;
        d[0] = d[1] = 0;
        while(i <= cost.length){
            if(i > 1){
                d[i] = Math.min(d[i-1] + cost[i-1],d[i-2] + cost[i-2]);
            }
            i ++;
        }
        return d[cost.length];
    }
}

Run the screenshot:

 

Guess you like

Origin blog.csdn.net/m0_63911789/article/details/129408353