码迷,mamicode.com
首页 >  
搜索关键字:preorder traversal    ( 1851个结果
【leetcode】Binary Tree Postorder Traversal
题目:...
分类:其他好文   时间:2014-08-28 09:44:59    阅读次数:165
LeetCode: Binary Tree Zigzag Level Order Traversal
LeetCode: Binary Tree Zigzag Level Order TraversalGiven a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to...
分类:其他好文   时间:2014-08-27 23:10:28    阅读次数:316
LeetCode: Binary Tree Level Order Traversal
LeetCode: Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level ...
分类:其他好文   时间:2014-08-27 21:55:48    阅读次数:326
39. Recover Binary Search Tree && Validate Binary Search Tree
思想: Morris traversal. Solution 1 : Preorder traversal Solution 2: Inorder traversal. Solution 3: Morris Traversal.
分类:其他好文   时间:2014-08-27 20:25:48    阅读次数:273
36. Construct Binary Tree from Inorder and Postorder Traversal && Construct Binary Tree from Preorder and Inorder Traversal
思想: 迭代。 说明: 这类问题,要求一个提供根节点,然后另一个序列(中序序列)可依据根节点分出左右子树。
分类:其他好文   时间:2014-08-27 20:20:38    阅读次数:198
37. Binary Tree Zigzag Level Order Traversal && Binary Tree Inorder Traversal
思路: 使用两个队列(一个可以顺序读,所以用vector模拟),每个队列放一层结点。 题解: 两种方法: 1. 使用栈: O(n) Time, O(n) Space。 2. Morris traversal (构造线索树), O(n) Time, O(1) Space.
分类:其他好文   时间:2014-08-27 20:16:18    阅读次数:227
35. Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II
思想: 若递归,传入层号。若迭代,使用队列,在每层结束时,加入一个标记。 思想: 目前用两种方法:1 同上,最后将结果反转一下。 2.先求出最大层数,再层序遍历。(也许还有更好的方法)
分类:其他好文   时间:2014-08-27 20:16:08    阅读次数:212
【Leetcode长征系列】Construct Binary Tree from Inorder and Postorder Traversal
原题: 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-21 17:22:24    阅读次数:138
Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extr...
分类:其他好文   时间:2014-08-20 22:47:33    阅读次数:297
【Leetcode】Binary Tree Preorder Traversal
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
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!