diff options
| author | Steve Lee <me@xiangyangli.com> | 2018-01-13 05:13:14 +0800 |
|---|---|---|
| committer | Steve Lee <me@xiangyangli.com> | 2018-01-13 05:13:14 +0800 |
| commit | a46ec300092c1ee8ccac629b7f335643f87662f5 (patch) | |
| tree | b03e20d905e6f583df626386164daf4aa5f81519 /Computer_Science/leetcode/746-min_cost_climbing_stairs.c~ | |
| parent | 79a9c52fa923fc78074d88463449a8b7f95ca3ef (diff) | |
| download | 42-a46ec300092c1ee8ccac629b7f335643f87662f5.tar.xz 42-a46ec300092c1ee8ccac629b7f335643f87662f5.zip | |
update
Diffstat (limited to 'Computer_Science/leetcode/746-min_cost_climbing_stairs.c~')
| -rw-r--r-- | Computer_Science/leetcode/746-min_cost_climbing_stairs.c~ | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Computer_Science/leetcode/746-min_cost_climbing_stairs.c~ b/Computer_Science/leetcode/746-min_cost_climbing_stairs.c~ new file mode 100644 index 0000000..44ffb6b --- /dev/null +++ b/Computer_Science/leetcode/746-min_cost_climbing_stairs.c~ @@ -0,0 +1,14 @@ +#define MIN(a, b) ((a) > (b) ? (a) : (b)) +int minCostClimbingStairs(int* cost, int costSize) { + int dp[costSize]; + if(costSize == 1) + return cost[0]; + dp[0] = 0; + dp[1] = 0; + + for(i = 2; i < costSize; i++) { + dp[i] = MIN(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]); + } + + return dp[costSize - 1]; +} |
