上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 23 下一页
摘要: 此题dfs用的出神入化 class Solution { public: vector<vector<int>> res; vector<int> temp; vector<vector<int>> subsets(vector<int>& nums) { dfs(nums,0); return r 阅读全文
posted @ 2021-07-17 16:22 三一一一317 阅读(29) 评论(0) 推荐(0)
摘要: 求解方法 知道了编辑距离的定义,那么如何求最小编辑距离呢?这里用到了动态规划的思想。 用例子来说明,假如我们要求解 jary和jerry的最小编辑距离,那么首先要创建如下矩阵: Φ j a r y Φ 0 1 2 3 4 j 1 e 2 r 3 r 4 y 5 这个矩阵什么意思呢?第一行是字符串ja 阅读全文
posted @ 2021-07-17 15:01 三一一一317 阅读(121) 评论(0) 推荐(0)
摘要: 和62题不同路径一样,使用dfs方法同样超时。 class Solution { public: vector<int> res; int minPathSum(vector<vector<int>>& grid) { int m = grid.size(); int n = grid[0].siz 阅读全文
posted @ 2021-07-17 14:17 三一一一317 阅读(28) 评论(0) 推荐(0)
摘要: 第一种方法 DFS 果然超时 class Solution { public: int count = 0; int uniquePaths(int m, int n) { vector<vector<bool>> visited(m, vector<bool>(n,false)); path(vi 阅读全文
posted @ 2021-07-17 13:45 三一一一317 阅读(28) 评论(0) 推荐(0)
摘要: 算法解析: class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { // 此题最关键的就是排序,如果不排序很难处理 sort(intervals.begin(), intervals.e 阅读全文
posted @ 2021-07-17 13:10 三一一一317 阅读(25) 评论(0) 推荐(0)
摘要: 第一种方式超时 class Solution { public: bool canJump(vector<int>& nums) { if(jump(nums,0)) return true; return false; } bool jump(vector<int> nums,int index) 阅读全文
posted @ 2021-07-17 11:57 三一一一317 阅读(39) 评论(0) 推荐(0)
摘要: class Solution { public: int climbStairs(int n) { vector<int> dp(n+1,0); if(n<2) return n; dp[0] = 0; dp[1] = 1; dp[2] = 2; // dp[i] 定义:到达当前i阶有dp[i]种不 阅读全文
posted @ 2021-07-16 20:54 三一一一317 阅读(22) 评论(0) 推荐(0)
摘要: 直接想到动态规划 class Solution { public: int maxSubArray(vector<int>& nums) { vector<int> dp(nums.size(),0); dp[0] = nums[0]; for(int i = 1; i < nums.size(); 阅读全文
posted @ 2021-07-16 20:43 三一一一317 阅读(34) 评论(0) 推荐(0)
摘要: class Solution { public: static bool cmp(string a, string b){ int sum_a = 0; int sum_b = 0; sort(a.begin(), a.end()); sort(b.begin(), b.end()); return 阅读全文
posted @ 2021-07-16 20:06 三一一一317 阅读(29) 评论(0) 推荐(0)
摘要: class Solution { public: void rotate(vector<vector<int>>& matrix) { int len = matrix.size(); // 先转化为对成矩阵 for(int i = 0; i < len;i++) for(int j = 0; j< 阅读全文
posted @ 2021-07-16 17:35 三一一一317 阅读(22) 评论(0) 推荐(0)
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 23 下一页