We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5b61949 commit f3f9204Copy full SHA for f3f9204
Dynamic Programming/746_Min_Cost_Climbing_Stairs.java
@@ -1,17 +1,14 @@
1
class Solution {
2
public int minCostClimbingStairs(int[] cost) {
3
- if (cost == null || cost.length == 0) {
4
- return 0;
5
- }
6
-
7
int[] dp = new int[cost.length];
+
8
dp[0] = cost[0];
9
dp[1] = cost[1];
10
11
for (int i = 2; i < cost.length; i++) {
12
dp[i] = cost[i] + Math.min(dp[i - 1], dp[i - 2]);
13
}
14
15
- return Math.min(dp[dp.length - 1], dp[dp.length - 2]);
+ return Math.min(dp[cost.length - 1], dp[cost.length - 2]);
16
17
0 commit comments