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...
分类:
其他好文 时间:
2014-08-11 11:45:02
阅读次数:
251
O(n) complexity, have a traversal for the tree. Get the information of all children, then traverse the tree again.
#include
#include
#include
#include
using namespace std;
class Node {
pub...
分类:
其他好文 时间:
2014-08-10 13:00:30
阅读次数:
238
注:后序遍历是较麻烦的一个,不可大意。关键两点: 1.要走到 p->left | p->right ==0, 2.每次出栈出两个结点。
分类:
其他好文 时间:
2014-08-10 01:45:39
阅读次数:
286
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
zigzag层序遍历树
For example:
Given binary...
分类:
其他好文 时间:
2014-08-09 23:19:59
阅读次数:
363
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
给出二叉树的中序遍历和后序遍历结果,恢复出二叉树。
后序遍历序列的最后一个元素值是二叉树的根节点的值,查找...
分类:
其他好文 时间:
2014-08-09 23:15:09
阅读次数:
312
Binary Tree Level Order Traversal IIGiven a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level...
分类:
其他好文 时间:
2014-08-08 23:53:16
阅读次数:
221
问题:输出二叉树的每一行的结点,从叶子到根/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(i...
分类:
其他好文 时间:
2014-08-06 22:04:02
阅读次数:
185
问题:从上到下打印二叉树的每一行分析:先搜出二叉树的高度,然后遍历高度,每次搜索一个高度class Solution {public: int dfs(TreeNode *root) { if(root==NULL) return 0; if(root->le...
分类:
其他好文 时间:
2014-08-06 21:53:32
阅读次数:
278
题目: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....
分类:
编程语言 时间:
2014-08-05 05:18:28
阅读次数:
242
题目:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).F....
分类:
编程语言 时间:
2014-08-05 05:18:08
阅读次数:
340