746. Min Cost Climbing Stairs

Easy
比较straightforward的dp题目

class Solution {
    public int minCostClimbingStairs(int[] cost) {
        int[] dp = new int[cost.length + 1];
        dp[0] = 0;
        dp[1] = 0;
        dp[2] = 0;
        for (int i = 3; i < dp.length; i++){
            dp[i] = Math.min(dp[i - 2] + cost[i - 3], dp[i - 1] + cost[i - 2]);
        }
        return Math.min(dp[cost.length] + cost[cost.length - 1], dp[cost.length - 1] + cost[cost.length - 2]);
    }
}

你可能感兴趣的:(746. Min Cost Climbing Stairs)