Skip to content

Commit f0f67db

Browse files
author
Dream
committed
[update] 746
1 parent 18b386c commit f0f67db

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
|804|[Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words/description/) | |Easy|
6161
|771|[Jewels and Stones](https://leetcode.com/problems/jewels-and-stones/description) | |Easy|
6262
|747|[Largest Number At Least Twice of Others](https://leetcode.com/problems/largest-number-at-least-twice-of-others/) | |Easy|
63-
|746|[Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/) | |Easy|
63+
|746|[Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/) | [Java_dream](./algorithms/minCostClimbingStairs/MinCostClimbingStairs.java)|Easy|
6464
|721|[Accounts Merge](https://leetcode.com/problems/accounts-merge/) | |Medium|
6565
|717|[1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters/) | |Easy|
6666
|714|[Best Time to Buy and Sell Stock with Transaction Fee](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee) | |Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author Dream
3+
*/
4+
public class MinCostClimbingStairs {
5+
public int minCostClimbingStairs(int[] cost) {
6+
if (cost == null || cost.length == 0) {
7+
return 0;
8+
}
9+
if (cost.length == 1) {
10+
return cost[0];
11+
}
12+
int[] dp = new int[cost.length];
13+
dp[0] = cost[0];
14+
dp[1] = cost[1];
15+
for (int i = 2; i < cost.length; i++) {
16+
dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];
17+
}
18+
return Math.min(dp[cost.length - 1], dp[cost.length - 2]);
19+
}
20+
}

0 commit comments

Comments
 (0)