From 294f461c12a761e54094911ed6c31265ea7c0305 Mon Sep 17 00:00:00 2001 From: Sadeep Nanda <70410776+SadeepNanda@users.noreply.github.com> Date: Sat, 30 Oct 2021 11:08:31 +0530 Subject: [PATCH] Create LeetCode746. Min Cost Climbing Stairs --- .../LeetCode746. Min Cost Climbing Stairs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 LeetCode/Problems/LeetCode746. Min Cost Climbing Stairs diff --git a/LeetCode/Problems/LeetCode746. Min Cost Climbing Stairs b/LeetCode/Problems/LeetCode746. Min Cost Climbing Stairs new file mode 100644 index 00000000..30ee4080 --- /dev/null +++ b/LeetCode/Problems/LeetCode746. Min Cost Climbing Stairs @@ -0,0 +1,18 @@ +class Solution { +public: + int dp[1001]; + int costcalc(int i,vector& cost) + { + if(i>=cost.size()) + return 0; + if(dp[i]!=-1) + return dp[i]; + int op1=cost[i]+costcalc(i+1,cost); + int op2=cost[i]+costcalc(i+2,cost); + return dp[i]=min(op1,op2); + } + int minCostClimbingStairs(vector& cost) { + memset(dp,-1,sizeof dp); + return(min(costcalc(0,cost),costcalc(1,cost))); + } +};