码迷,mamicode.com
首页 >  
搜索关键字:binary trees    ( 12390个结果)
递归的应用--求二叉树最大深度和最小深度
【求最大深度】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
POJ 2665 Trees(水题)
【题意简述】:就是有一段路上有和长度加一的值相等的数目,现在要在这条路上修路,所以要砍掉一些树,问剩下了多少树。 【分析】:很简单,注意一的处理就好。 //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
Leetcode_num8_Binary Tree Preorder Traversal
题目:Given a binary tree, return the preorder traversal of its nodes' values. 此题即为二叉树的前序遍历,递归的方法很简单:先节点再左子树再右子树;迭代的方法可以利用栈存储来完成遍历过程。 补充递归与迭代的区别:许多问题是以递归的形式进行解释的,这只是因为它比非递归形式更为清晰。但是,这些问题的迭代往往比递归实现效率更...
分类:其他好文   时间:2014-09-24 11:24:56    阅读次数:206
HDU-1701 Binary Tree Traversals
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
Java数据结构四之——二叉树的前、中、后序遍历
程序来自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
UVa 122 Trees on the level(建树,层次遍历)
题意  建树并层次遍历输出  (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
Leetcode_num6_Unique Binary Search Trees
题目: 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
【LeetCode】Sum Root to Leaf Numbers 解题报告
【题目】 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
Maximum Depth of Binary Tree
[leetcode]Given a binary tree, find its maximum depth....
分类:其他好文   时间:2014-09-22 13:24:42    阅读次数:114
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!