From dc1f0c4c0096013799416664894c5194dc7e1f52 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- works/solutions/leetcode/cpp/746.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 works/solutions/leetcode/cpp/746.cpp (limited to 'works/solutions/leetcode/cpp/746.cpp') diff --git a/works/solutions/leetcode/cpp/746.cpp b/works/solutions/leetcode/cpp/746.cpp deleted file mode 100644 index 72ffd9f..0000000 --- a/works/solutions/leetcode/cpp/746.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include - -using std::vector; - -#include - -class Solution -{ -public: - int minCostClimbingStairs(vector &cost) - { - int count = cost.size(); - - // Total cost for index i means min cost of stepping through the number i stair, - // after which you are free to jump two or one stair. - // total_costs[i] is based on total_costs[i - 2] and total_costs[i - 1]. - // Note: - // This is not min cost to step above the number i stair, which has no simple dependency - // relationship because based on whether it steps through the last step there are two situation. - // However with the restriction of stepping through that last stair, there is a - // dependency relationship. And we can easily get the final result by comparing total_costs[count - 2] - // and total_costs[count - 1]. But not just use total_costs[count - 1]. - vector total_costs(count); - - total_costs[0] = cost[0]; - total_costs[1] = cost[1]; - - for (int i = 2; i < count; i++) - { - total_costs[i] = std::min(total_costs[i - 2], total_costs[i - 1]) + cost[i]; - } - - return std::min(total_costs[count - 2], total_costs[count - 1]); - } -}; -- cgit v1.2.3