aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science/leetcode/746-min_cost_climbing_stairs.c
blob: 74cc72ba00fbb2caffa5b2ba3309c658bb014fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define MIN(a, b) ((a) > (b) ? (b) : (a))
int minCostClimbingStairs(int* cost, int costSize) {
	int dp[costSize + 1];
	if(costSize == 1)
		return cost[0];
	dp[0] = 0;
	dp[1] = 0;

	for(int i = 2; i < costSize + 1; i++) {
		dp[i] = MIN(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);
	}

	return dp[costSize];
}