[C++] 18ms two liner by DP, TC-O(n), SC-O(1)


  • 0
    A

    '''
    class Solution {
    public:
    int minCostClimbingStairs(vector<int>& cost) {
    for (int i = 2; i < cost.size(); ++i) { cost[i] = cost[i] + min(cost[i - 1], cost[i - 2]); }
    return min(cost[cost.size() - 1], cost[cost.size() - 2]);
    }
    };
    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.