mirror of
https://github.com/20kaushik02/leetcode-gulag.git
synced 2025-12-06 08:54:07 +00:00
day 37: 746-min-cost-climbing-stairs
This commit is contained in:
parent
1168f54602
commit
fbcb849210
10
746-min-cost-climbing-stairs/driver.cpp
Normal file
10
746-min-cost-climbing-stairs/driver.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "soln.hpp"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
vector<int> costs{1, 100, 1, 1, 1, 100, 1, 1, 100, 1};
|
||||||
|
int answer = 6;
|
||||||
|
Solution soln;
|
||||||
|
cout << "Found min cost correctly? " << soln.test(costs, answer) << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
16
746-min-cost-climbing-stairs/soln.cpp
Normal file
16
746-min-cost-climbing-stairs/soln.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "soln.hpp"
|
||||||
|
|
||||||
|
int Solution::minCostClimbingStairs(vector<int> &cost)
|
||||||
|
{
|
||||||
|
int n = cost.size();
|
||||||
|
for (int i = 2; i < n; i++)
|
||||||
|
{
|
||||||
|
cost[i] += min(cost[i - 1], cost[i - 2]);
|
||||||
|
}
|
||||||
|
return min(cost[n - 1], cost[n - 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Solution::test(vector<int> &cost, int answer)
|
||||||
|
{
|
||||||
|
return minCostClimbingStairs(cost) == answer;
|
||||||
|
}
|
||||||
8
746-min-cost-climbing-stairs/soln.hpp
Normal file
8
746-min-cost-climbing-stairs/soln.hpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
using namespace std;
|
||||||
|
class Solution
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int minCostClimbingStairs(vector<int> &cost);
|
||||||
|
bool test(vector<int> &cost, int answer);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user