Given preorder and inorder (Inorder and Postorder) traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
前序和后序的特点是根结点要么在最前面、要么在最后...
分类:
其他好文 时间:
2015-06-22 09:56:49
阅读次数:
138
Given a complete binary tree, count the number of nodes.
Definition of a complete binary tree from Wikipedia:
In a complete binary tree every level, except possibly the last, is completely filled,...
分类:
其他好文 时间:
2015-06-22 09:55:34
阅读次数:
149
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe...
分类:
其他好文 时间:
2015-06-22 09:55:14
阅读次数:
139
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 20
...
分类:
其他好文 时间:
2015-06-21 15:49:22
阅读次数:
131
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
1
/ 2 2
/ \ / 3 4 4 3
But the f...
分类:
其他好文 时间:
2015-06-21 14:37:26
阅读次数:
145
反转二叉树:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
...
分类:
其他好文 时间:
2015-06-21 13:12:18
阅读次数:
147
box2d dynamic treedynamic tree 是一颗 full binary trees, 即非叶子节点必须有两个子节点(注:full binary trees和大学老师讲的满二叉树,完全二叉树不同)那么如果构建树?先看源码 while (m_nodes[index].IsLeaf(...
分类:
其他好文 时间:
2015-06-20 20:44:49
阅读次数:
249
二叉树(binary)是一种特殊的树。二叉树的每个节点最多只能有2个子节点:二叉树由于二叉树的子节点数目确定,所以可以直接采用上图方式在内存中实现。每个节点有一个左子节点(left children)和右子节点(right children)。左子节点是左子树的根节点,右子节点是右子树的根节点。如果...
分类:
编程语言 时间:
2015-06-20 18:25:18
阅读次数:
162
Description:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each...
分类:
其他好文 时间:
2015-06-20 16:57:34
阅读次数:
74
Description: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 ...
分类:
其他好文 时间:
2015-06-20 16:55:12
阅读次数:
118