==========================努力奋斗财源广进==========================
给定一个整数数组 cost ,其中 cost[i] 是从楼梯第i 个台阶向上爬需要支付的费用,下标从0开始。一旦你支付此费用,即可选择向上爬一个或者两个台阶。
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param cost int整型一维数组
* @return int整型
*/
public int minCostClimbingStairs (int[] cost) {
// write code here
int[] dp = new int[cost.length +1];
int len = cost.length;
for(int i = 2; i <= len; i++)
{
dp[i] = Math.min(dp[i-1]+ cost[i-1], dp[i-2]+cost[i-2]);
}
return dp[len];
}
}
//待定
评论区记录复习记录
评论