摘要: https://www.nowcoder.com/question/next?pid=27976983&qid=235785&tid=45624435 #include <iostream> using namespace std; int main(){ int sum=0; int temp; 阅读全文
posted @ 2021-07-17 20:20 三一一一317 阅读(91) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2021-07-17 19:37 三一一一317 阅读(25) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2021-07-17 19:27 三一一一317 阅读(32) 评论(0) 推荐(0)
摘要: 要找出所有二叉搜索树,可用动态规划的思想 以1 ... n 为节点组成的二叉搜索树,不同的树在于根结点的不同和左右子树的不同 根结点不同,可能有n种情况,以1为根结点,以2为根结点...类推到以n为根结点,共有n种情况,区分了根节点不同后,剩下的 就是左右子树不同了,而左右子树的不同二叉树则是一个相 阅读全文
posted @ 2021-07-17 18:58 三一一一317 阅读(26) 评论(0) 推荐(0)
摘要: 下面的dfs在剑指offer上没毛病,在leetcode上超时 class Solution { public: bool exist(vector<vector<char>>& board, string word) { int m = board.size(); int n = board[0] 阅读全文
posted @ 2021-07-17 17:02 三一一一317 阅读(27) 评论(0) 推荐(0)
摘要: 此题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 阅读(31) 评论(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 阅读(40) 评论(0) 推荐(0)