题目:Binary Tree Inorder Traversal二叉树的中序遍历,和前序、中序一样的处理方式,代码见下: 1 struct TreeNode { 2 int val; 3 TreeNode* left; 4 TreeNode* ...
分类:
其他好文 时间:
2014-10-11 22:03:26
阅读次数:
233
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
/**
* Definition for b...
分类:
其他好文 时间:
2014-10-08 10:45:45
阅读次数:
106
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).
For example:
Given binary ...
分类:
其他好文 时间:
2014-10-06 16:46:00
阅读次数:
165
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
/**
* Definition for binary tree
* struct TreeNode {
...
分类:
其他好文 时间:
2014-10-06 14:46:30
阅读次数:
202
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
/**
* Definition for binary tree
* struct TreeNode {...
分类:
其他好文 时间:
2014-10-06 14:45:50
阅读次数:
178
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).
For example:
Given binary tree {3,9,20,#,#,15,7},
...
分类:
其他好文 时间:
2014-10-05 23:07:59
阅读次数:
214
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Soluti...
分类:
其他好文 时间:
2014-10-04 15:07:46
阅读次数:
162
Binary Tree PreOrder Traversal:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ ...
分类:
编程语言 时间:
2014-10-04 02:51:25
阅读次数:
285
把三个二叉树遍历的题放在一起了。递归写法太简单,就不再实现了,每题实现了两种非递归算法。一种是利用栈,时间和空间复杂度都是O(n)。另一种是借助线索二叉树,也叫Morris遍历,充分利用树中节点的空指针域。先序:Binary Tree Preorder TraversalGiven a binary...
分类:
其他好文 时间:
2014-10-03 23:07:55
阅读次数:
341
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).
For example:
Given binary tree {3,9,20,#,#,15,7},
...
分类:
其他好文 时间:
2014-10-03 19:41:45
阅读次数:
189