day 37: 746-min-cost-climbing-stairs

This commit is contained in:
Kaushik Narayan R 2023-11-10 12:06:49 -07:00
parent 1168f54602
commit fbcb849210
3 changed files with 34 additions and 0 deletions

View 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;
}

View 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;
}

View 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);
};