问题描述
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
Note: Recurs...
分类:
其他好文 时间:
2014-09-02 17:50:45
阅读次数:
136
Binary Tree Preorder TraversalGiven a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ ...
分类:
其他好文 时间:
2014-08-31 18:34:41
阅读次数:
180
思想: Morris traversal.
Solution 1 : Preorder traversal
Solution 2: Inorder traversal.
Solution 3: Morris Traversal.
分类:
其他好文 时间:
2014-08-27 20:25:48
阅读次数:
273
思想: 迭代。
说明: 这类问题,要求一个提供根节点,然后另一个序列(中序序列)可依据根节点分出左右子树。
分类:
其他好文 时间:
2014-08-27 20:20:38
阅读次数:
198
Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not...
分类:
其他好文 时间:
2014-08-20 14:01:43
阅读次数:
202
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-08-17 16:54:02
阅读次数:
160
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-08-16 23:48:31
阅读次数:
333
1.非递归先序遍历要点:总是先访问根root,而将root的右结点压入栈中,当root没有左结点时,取出栈顶元素给root。void preorder(node* root){ if(root==NULL) return; stack s; while(true){ ...
分类:
其他好文 时间:
2014-08-16 12:19:30
阅读次数:
171
#define NULL 0class Solution {public: vector preorderTraversal(TreeNode *root) { stack s; vector v1; if(root!=NULL) s.p...
分类:
其他好文 时间:
2014-08-14 13:35:48
阅读次数:
210