码迷,mamicode.com
首页 >  
搜索关键字:preorder traversal    ( 1851个结果
LeetCode: Binary Tree Level Order Traversal II [107]
【题目】 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}, 3 / 9 20 / 15 7 return its b...
分类:其他好文   时间:2014-06-20 09:42:30    阅读次数:224
【Leetcode】Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 2 / 3 return [3,2,1]. Note: Recursive solut...
分类:其他好文   时间:2014-06-15 19:06:52    阅读次数:166
[LeetCode] Binary Tree Preorder/Inorder/Postorder Traversal
前中后遍历 递归版 1 /* Recursive solution */ 2 class Solution { 3 public: 4 vector preorderTraversal(TreeNode *root) { 5 6 vector resul...
分类:其他好文   时间:2014-06-10 19:38:03    阅读次数:219
Binary Tree Preorder Traversal
第一次看到accept,心里有点小开心/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode...
分类:其他好文   时间:2014-06-10 11:53:41    阅读次数:241
Binary Tree Zigzag Level Order Traversal
题目 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: G...
分类:其他好文   时间:2014-06-08 17:29:07    阅读次数:315
Binary Tree Level Order Traversal
题目  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 / \...
分类:其他好文   时间:2014-06-08 16:38:02    阅读次数:194
【leetcode】Construct Binary Tree from Preorder and Inorder Traversal
问题: 给定二叉树的前序和中序遍历,重构这课二叉树. 分析: 前序、中序、后序都是针对于根结点而言,所以又叫作先根、中根、后根(当然不是高跟)。 前序:根  左 右 中序:左  根 右 对二叉树,我们将其进行投影,就会发现个有趣的事: 发现投影后的顺序,恰好是中序遍历的顺序,这也就是为什么在构造二叉树的时候,一定需要知道中序遍历,因为中序遍历决定了结点间的相对左右位置关系。所...
分类:其他好文   时间:2014-06-08 15:20:12    阅读次数:214
Binary Tree Preorder Traversal
1. 递归解法 2. 非递归解法(空间复杂度O(n)和O(1))...
分类:其他好文   时间:2014-06-08 10:47:37    阅读次数:139
【leetcode】Construct Binary Tree from Inorder and Postorder Traversal
问题: 由中序和后序遍历构造二叉树。 分析: Construct Binary Tree from Preorder and Inorder Traversal //实现 TreeNode *addNode(vector &inorder, int s1, int end1, vector &postorder, int s2, int end2) { ...
分类:其他好文   时间:2014-06-08 09:56:52    阅读次数:206
Binary Tree Level Order Traversal II
题目 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...
分类:其他好文   时间:2014-06-08 09:23:34    阅读次数:230
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!