摘要: 我自己是通过深度优先搜索实现的,虽然效率不高但是思路很简单 class Solution { public: vector<vector<int>> combine(int n, int k) { vector<vector<int> > v; DFS(1,v,n,k); return v; } p 阅读全文
posted @ 2020-09-08 19:25 是水泵呢 阅读(104) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> #include<queue> #include<vector> using namespace std; const int N = 110; struct node{ int deep; vector<int> child; }Node[N];//1..N-1 阅读全文
posted @ 2020-09-08 18:56 是水泵呢 阅读(54) 评论(0) 推荐(0) 编辑
摘要: #include<cstdio> #include<vector> #include<math.h> #include<queue> using namespace std; const int N = 100010; struct node{ bool isretailer=true; vecto 阅读全文
posted @ 2020-09-08 18:29 是水泵呢 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 本题的重点是利用层序遍历维持树每个结点的深度数据的更新,这是层序遍历的一个重要应用。 注意:计算叶子节点的次方时用#include<math.h>下的pow函数,不然最后一个样例会超时 #include<cstdio> #include<vector> #include<queue> #includ 阅读全文
posted @ 2020-09-08 17:09 是水泵呢 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 如果不确定范围可以自己画图解释 class Solution { public: TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) { TreeNode* root = build(preorder,inorder,0, 阅读全文
posted @ 2020-09-07 14:58 是水泵呢 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 1.递归 class Solution { public: vector<int> inorderTraversal(TreeNode* root) { vector<int> inOrder; inorder(root,inOrder); return inOrder; } void inorde 阅读全文
posted @ 2020-09-07 14:40 是水泵呢 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 思考:由于前序遍历的思路与深度优先搜索类似,所以前序遍历的迭代形式与深度优先搜索的迭代形式类似。 而深度优先的过程与出栈入栈的过程很类似,我们就可以利用栈来完成深度优先搜索的迭代 1.递归 class Solution { public: vector<int> preorder(Node* roo 阅读全文
posted @ 2020-09-07 11:23 是水泵呢 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 照班一下海明效验码的定义: 海明码(Hamming Code)是利用奇偶性来检错和纠错的校验方法。海明码的构成方法是在数据位之间的确定位置插入k个校验位,通过扩大吗距来实现检错和纠错。对于数据位m的数据,加入k位的校验码,它应满足: 2^k>m+k+1 我一直感觉很难理解是因为校验位的位置每次都是2 阅读全文
posted @ 2020-09-07 00:13 是水泵呢 阅读(369) 评论(0) 推荐(0) 编辑
摘要: 反转树可以在构建树的过程中完成 层序遍历的方式类似于BFS #include<cstdio> #include<algorithm> #include <vector> #include<queue> using namespace std; const int N = 10; struct nod 阅读全文
posted @ 2020-09-02 23:00 是水泵呢 阅读(70) 评论(0) 推荐(0) 编辑
摘要: 要认清该题的本质是已知先序序列和中序序列,求后序序列 #include<cstdio> #include<stack> #include<vector> #include<string.h> using namespace std; const int N = 31; struct node{ in 阅读全文
posted @ 2020-09-02 22:15 是水泵呢 阅读(102) 评论(0) 推荐(0) 编辑