240
笔下虽有千言,胸中实无一策
摘要: 题解 Easy 动态规划 class Solution { public: int minCostClimbingStairs(vector<int>& cost) { if(cost.empty()) return 0; if(cost.size() == 1) return 0; if(cost 阅读全文
posted @ 2020-09-24 07:27 CasperWin 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 动态规划 Easy 动态规划 class Solution { public: int climbStairs(int n) { if(n == 1) return 1; vector<int> dp(n+1); dp[0] = 0; dp[1] = 1; dp[2] = 2; for(int i 阅读全文
posted @ 2020-09-24 06:51 CasperWin 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium 动态规划 将环形数组分解两个数组去处理,即[0:n-2]和[1:n-1]。最后取结果的较大值。 class Solution { public: int rob(vector<int>& nums) { if(nums.empty()) return 0; if(nums.siz 阅读全文
posted @ 2020-09-24 06:44 CasperWin 阅读(73) 评论(0) 推荐(0) 编辑
摘要: 题解 动态规划 Easy class Solution { public: int rob(vector<int>& nums) { if(nums.empty()) return 0; if(nums.size() == 1) return nums[0]; if(nums.size() == 2 阅读全文
posted @ 2020-09-24 06:20 CasperWin 阅读(73) 评论(0) 推荐(0) 编辑
摘要: 题解 动态规划。 Easy class Solution { public: int numWays(int n, int k) { if(n == 0) return 0; if(n == 1) return k; int num = 0; // dp1[i]: the number of way 阅读全文
posted @ 2020-09-24 05:59 CasperWin 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 题解 动态规划,Hard级别。 Paint House 的升级版,如果颜色数量不是三种,而是若干种。直接套用256的思路,问题得解。 class Solution { public: int minCostII(vector<vector<int>>& costs) { if(costs.empty 阅读全文
posted @ 2020-09-24 03:08 CasperWin 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 题解 动态规划,Easy级别。 动态规划题,重点是找到传递公式,思路见注释。 class Solution { public: int minCost(vector<vector<int>>& costs) { if(costs.empty()) return 0; int n = costs.si 阅读全文
posted @ 2020-09-24 01:37 CasperWin 阅读(53) 评论(0) 推荐(0) 编辑