← Back to LeetCode Notes

746. Min Cost Climbing Stairs

easy · array · dynamic-programming · solved 2026.07.13 · 11 sec read

View on LeetCode ↗
C++
class Solution {public:    int minCostClimbingStairs(vector<int>& cost) {        std::vector<int> save(1002, 0);        for (int i = 2; i <= cost.size(); i++) {            save[i] =                min(save[i - 1] + cost[i - 1], save[i - 2] + cost[i - 2]);        }        return save[cost.size()];    }};

Another simple one, I was trying to over complicate it with recursion at first. could have worked but the memoization would be hard. doing it with the iteratively part was easier. i liked doing it.