【求最大深度】Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
这里说的最大深度是指最深叶子节点到根节点的路径长度
...
分类:
其他好文 时间:
2014-09-24 16:09:37
阅读次数:
200
【题意简述】:就是有一段路上有和长度加一的值相等的数目,现在要在这条路上修路,所以要砍掉一些树,问剩下了多少树。
【分析】:很简单,注意一的处理就好。
//216K 79Ms
#include
using namespace std;
int main()
{
int len,n,s,e;
while(cin>>len>>n)
{
int sum = 0;
if(len == ...
分类:
其他好文 时间:
2014-09-24 16:07:07
阅读次数:
193
题目:Given a binary tree, return the preorder traversal
of its nodes' values.
此题即为二叉树的前序遍历,递归的方法很简单:先节点再左子树再右子树;迭代的方法可以利用栈存储来完成遍历过程。
补充递归与迭代的区别:许多问题是以递归的形式进行解释的,这只是因为它比非递归形式更为清晰。但是,这些问题的迭代往往比递归实现效率更...
分类:
其他好文 时间:
2014-09-24 11:24:56
阅读次数:
206
http://acm.hdu.edu.cn/showproblem.php?pid=1710已知先序和中序遍历,求后序遍历二叉树。思路:先递归建树的过程,后后序遍历。Binary Tree TraversalsTime Limit: 1000/1000 MS (Java/Others)Memory ...
分类:
其他好文 时间:
2014-09-23 22:38:55
阅读次数:
237
程序来自Program Creek前Preorder binary tree traversal is a classic interview problem about trees. The key to solve this problem is to understand the follow...
分类:
编程语言 时间:
2014-09-23 22:37:05
阅读次数:
337
原题:
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
For example:
Given binary tree {3,9,20,#,#,15,7},
3
/ 9 ...
分类:
其他好文 时间:
2014-09-23 20:29:17
阅读次数:
243
题意 建树并层次遍历输出 (data,pos) pos表示改节点位置 L代表左儿子 R代表右儿子
建树很简单 开始在根节点 遇到L往左走遇到R往右走 节点不存在就新建 走完了就保存改节点的值 输出直接bfs就行了了
#include
#include
#include
using namespace std;
const int maxn = 300;
char...
分类:
其他好文 时间:
2014-09-23 12:28:54
阅读次数:
234
题目:
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?
For example,
Given n = 3, there are a total of 5 unique BST's.
1 3 3 2...
分类:
其他好文 时间:
2014-09-22 20:55:03
阅读次数:
203
【题目】
Given a binary tree containing digits from 0-9 only, each root-to-leaf
path could represent a number.
An example is the root-to-leaf path 1->2->3 which represents the number 123.
Fin...
分类:
其他好文 时间:
2014-09-22 19:30:53
阅读次数:
175
[leetcode]Given a binary tree, find its maximum depth....
分类:
其他好文 时间:
2014-09-22 13:24:42
阅读次数:
114