• 문제 링크
Min Cost Climbing Stairs - LeetCode
Can you solve this real interview question? Min Cost Climbing Stairs - You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the ste
leetcode.com
• 풀이 코드
public class Solution {
public int minCostClimbingStairs(int[] cost) {
int a = cost[0], b = cost[1];
for (int i = 2; i < cost.length; i++) {
int c = cost[i] + Math.min(a, b);
a = b;
b = c;
}
return Math.min(a, b);
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 748. Shortest Completing Word - Java (0) | 2026.10.10 |
|---|---|
| [LeetCode] 747. Largest Number At Least Twice of Others - Java (0) | 2026.10.09 |
| [LeetCode] 744. Find Smallest Letter Greater Than Target - Java (0) | 2026.10.07 |
| [LeetCode] 733. Flood Fill - Java (0) | 2026.10.06 |
| [LeetCode] 728. Self Dividing Numbers - Java (0) | 2026.10.05 |
댓글