240
笔下虽有千言,胸中实无一策
上一页 1 2 3 4 5 6 7 8 ··· 17 下一页
摘要: 题解 Medium | Backtracking class Solution { public: vector<vector<int>> combinationSum2(vector<int>& candidates, int target) { sort(candidates.begin(), 阅读全文
posted @ 2020-09-29 12:08 CasperWin 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium | Backtracking class Solution { public: vector<vector<int>> combinationSum(vector<int>& candidates, int target) { vector<vector<int>> sols; 阅读全文
posted @ 2020-09-29 12:00 CasperWin 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium | Backtracking 经典的排列组合题,使用回溯法。必须熟练。 class Solution { public: vector<vector<int>> combine(int n, int k) { vector<vector<int>> combinations; v 阅读全文
posted @ 2020-09-29 11:49 CasperWin 阅读(65) 评论(0) 推荐(0) 编辑
摘要: 题解 Easy | Backtracking/DFS 这道题被标记为Easy级别,可是我感觉并不简单,还是花了一些时间的。 class Solution { public: vector<string> readBinaryWatch(int num) { set<string> ret; vect 阅读全文
posted @ 2020-09-25 09:49 CasperWin 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 题解 Hard | Backtracking/DFS 这道题使用标准的Backtracking套路,不难得解。一开始没有注意两点,导致错误: 起点不一定是在左上角的grid[0][0],而是需要根据条件找出来; 每一个非障碍位置都需要走一次,这就不同于之前的 Unique Paths 的题,有些格子 阅读全文
posted @ 2020-09-25 08:44 CasperWin 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium 动态规划 class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { if(obstacleGrid.empty()) return 0; int m = o 阅读全文
posted @ 2020-09-25 03:22 CasperWin 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 题解 Easy. 动态规划。 class Solution { public: int uniquePaths(int m, int n) { vector<vector<int>> dp(m, vector<int>(n)); for(int i = 0; i < m; i++) dp[i][0] 阅读全文
posted @ 2020-09-25 03:13 CasperWin 阅读(58) 评论(0) 推荐(0) 编辑
摘要: 题解 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) 编辑
摘要: 题解 双指针法,移动窗口法(Sliding Window) 很重要的题。 这道题要求地很细,移动窗口的时候,要同时记录,开始位置、长度和包含目标字符的个数count。 class Solution { public: string minWindow(string s, string t) { in 阅读全文
posted @ 2020-09-20 10:04 CasperWin 阅读(93) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 17 下一页