Skip to content

Commit bb4f3ce

Browse files
committed
feat : leetCode 비용이 적게드는 계단 오르기
1 parent 68bc1f7 commit bb4f3ce

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/main/java/sgyj/leetcode/Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626

2727
- [200. Number of Islands](https://leetcode.com/problems/number-of-islands/description/)
2828
- [1091. Shortest Path in Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix/)
29-
- [841. Keys and Rooms](https://leetcode.com/problems/keys-and-rooms/description/)
29+
- [841. Keys and Rooms](https://leetcode.com/problems/keys-and-rooms/description/)
30+
31+
## DP
32+
33+
- [746. Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/description/)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package sgyj.leetcode.yeji.section6;
2+
3+
public class Solution746 {
4+
5+
public static int minCostClimbingStairs(int[] cost) {
6+
int[] minCost = new int[cost.length+1];
7+
int answer = 0;
8+
9+
for(int i=0; i<cost.length; i++){
10+
minCost[i] = cost[i];
11+
}
12+
13+
for(int i=2; i<minCost.length; i++){
14+
int target1 = minCost[i] + minCost[i-1];
15+
int target2 = minCost[i] + minCost[i-2];
16+
minCost[i] = Math.min(target1,target2);
17+
}
18+
19+
return minCost[minCost.length-1];
20+
}
21+
22+
public static void main ( String[] args ) {
23+
int[] cost = {1,100,1,1,1,100,1,1,100,1};
24+
System.out.println(minCostClimbingStairs( cost ));
25+
}
26+
}

0 commit comments

Comments
 (0)