#include
#include
#include
using namespace std; //二叉树结点
typedef struct BiTNode{
//数据
char data;
//左右孩子指针
struct BiTNode *lchild,*rchild;
}BiTN...
分类:
编程语言 时间:
2015-06-15 09:22:17
阅读次数:
154
http://codevs.cn/problem/1029/给出一棵二叉树(节点是小写字符)的按照先序遍历和后续遍历得到的字符串,其实就是求有多少和二叉树的先序遍历和后序遍历满足这两个字符串。区间dp:dp(l, r, a, b)表示s字符串的(l, r)段和t字符串的(a, b)段相匹配的方案数。...
分类:
其他好文 时间:
2015-06-14 22:40:20
阅读次数:
153
二叉树的遍历方法有多种,最常用的有中序遍历、先序遍历和后序遍历。毫无例外,这三种遍历方法都是基于递归/迭代的思想为了更好的说明三种遍历,结合图片。假设现在存在{1,3,5,7,9,2,4,6,8,10}的一个完全二叉树中序遍历:遍历时先尝试访问当前结点的左子结点,如果左子结点不存在,则读取当前结点的...
分类:
其他好文 时间:
2015-06-14 18:10:42
阅读次数:
147
#include
#include
#include
#include
#include
using namespace std;
const int N = 10000 + 10;
const int M = 50000 + 10;
int n, m;
int head1[N], tot1, head2[N], tot2;
bool vis[N];
vector v; //后序访问...
分类:
其他好文 时间:
2015-06-13 14:21:05
阅读次数:
104
Given a binary tree, return the postorder traversal of its nodes’ values.For example:
Given binary tree {1,#,2,3}, 1
2
/
3return [3,2,1].Note: Recursive solution is trivial, could...
分类:
其他好文 时间:
2015-06-13 11:23:14
阅读次数:
113
描述树的遍历即给出一个指向树的指针,访问树中的每一个节点。树的遍历有三种基本遍历方式,分别是前序(preorder)、中序(inorder)、后序(postorder)。...
分类:
其他好文 时间:
2015-06-12 19:28:02
阅读次数:
143
The key of this problem is that we need not build the tree from scratch. In fact, we can direct obtain its post-order traversal results in a recursive...
分类:
其他好文 时间:
2015-06-07 17:19:23
阅读次数:
117
重建二叉树时间限制:1000ms | 内存限制:65535KB难度:3描述题目很简单,给你一棵二叉树的后序和中序序列,求出它的前序序列(So easy!)。输入输入有多组数据(少于100组),以文件结尾结束。每组数据仅一行,包括两个字符串,中间用空格隔开,分别表示二叉树的后序和中序序列(字符串长度小...
分类:
其他好文 时间:
2015-06-06 22:02:36
阅读次数:
169
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [3,2,1].
Note: Recursive solut...
分类:
其他好文 时间:
2015-06-06 13:38:24
阅读次数:
138
题目:输入一棵二叉树的根结点,判断该树是不是平衡二叉树。某二叉树中任意结点的左右子树的深度相差不超过1,那么它就是一棵二叉树。
我们很容易就能想到一个代码简洁却性能不佳的思路:在遍历树的每个结点的时候,调用函数TreeDpth得到它的左右子树的深度。如果每个结点的左右子树的深度相差都不超过1,按照定义它就是一棵平衡的二又树。
较好的思路是:用后序遍历的方式遍历整...
分类:
其他好文 时间:
2015-06-04 22:46:13
阅读次数:
155