Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
分类:
编程语言 时间:
2014-07-12 13:13:24
阅读次数:
195
语言:Python描述:使用递归实现 1 class Solution: 2 # @return an integer 3 def numTrees(self, n): 4 if n == 0: 5 return 0 6 eli...
分类:
其他好文 时间:
2014-07-11 23:44:08
阅读次数:
216
题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.说明: 1)二叉树可.....
分类:
其他好文 时间:
2014-07-11 21:07:27
阅读次数:
273
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.说明: 1)实现与.....
分类:
其他好文 时间:
2014-07-11 20:40:38
阅读次数:
198
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; ...
分类:
其他好文 时间:
2014-07-11 08:58:23
阅读次数:
207
Description
Let us consider a special type of a binary search tree, called a cartesian tree. Recall that a binary search tree is a rooted ordered binary tree, such that for its every node x the fol...
分类:
其他好文 时间:
2014-07-11 00:12:52
阅读次数:
379
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:递归。主要是注意调用时起...
分类:
其他好文 时间:
2014-07-10 14:40:07
阅读次数:
196
二叉排序树(Binary Sort Tree):或者是一颗空树,或者是具有以下性质的树:(1)若它的左子树不空,则左子树上所以结点的值均小于它的根节点的值;(2)若它的右子树不空,则右子树上的所以结点的值均大于它的根节点的值;(3)它的左、右子树也分别是二叉排序树。
二叉排序树的基本操作均可以在O(h)时间内完成(算法导论p165)。
相关操作代码如下:
int InsertBST(BiTr...
分类:
其他好文 时间:
2014-07-09 13:12:09
阅读次数:
160
题目
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
For example:
Given the below binary tree ...
分类:
其他好文 时间:
2014-07-09 10:32:42
阅读次数:
151
这个点POJ挂了,代码没法提交,先存到这里,明天再提交试试看。
//#define DEBUG
#include
#define maxn 100002
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
__int64 tree[maxn << 2], arr[maxn], lazy[maxn << 2];...
分类:
其他好文 时间:
2014-07-09 09:41:55
阅读次数:
213