码迷,mamicode.com
首页 >  
搜索关键字:postorder    ( 397个结果
Leetcode #145 Binary Tree Postorder Traversal
题目链接:https://leetcode.com/problems/binary-tree-postorder-traversal/(非递归实现)二叉树的后序遍历。 1 class Solution 2 { 3 public: 4 vector postorderTraversal(Tre...
分类:其他好文   时间:2015-04-05 23:24:15    阅读次数:160
[LeetCode] Binary Tree Postorder Traversal
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 ret...
分类:其他好文   时间:2015-04-05 16:04:34    阅读次数:151
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. 根据二叉树的中序遍历和后续遍历结果构造二叉树。思路分析: 这道题和上道题《 Leetcode: Constr...
分类:其他好文   时间:2015-04-04 00:02:22    阅读次数:180
leetcode_106_Construct Binary Tree from Inorder and Postorder Traversal
思路: 1.将中序遍历序列和其对应的下标存储到一个map中,方便下面的查找 2.递归选取后序序列的倒数第一个元素作为树的根节点,然后查找根节点在后序序列中位置inorderIndex,endInorder-inorderIndex可以得到右子树的长度 3.根据右子树的长度和endPreOrder可以求出后序序列中右子树的起始位置 4.从上面可以求出左右子树的后序序列和中序序列的起始位置,递归调用建树过程即可。...
分类:其他好文   时间:2015-04-03 15:16:31    阅读次数:89
[LeetCode] Construct Binary Tree from Inorder and Postorder Traversal
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 t...
分类:其他好文   时间:2015-04-03 01:35:34    阅读次数:131
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 solution is trivial,...
分类:其他好文   时间:2015-04-02 22:39:03    阅读次数:180
leetcode:Binary Tree Postorder Traversal
class Solution { public: vector postorderTraversal(TreeNode *root) { vector res; stack>s; TreeNode *p = root; while(p!=NULL||!s.empty()) { while...
分类:其他好文   时间:2015-04-02 19:02:48    阅读次数:117
Construct binary tree form postorder and inorder--LeetCode
和上面的题目相似 思路也是类似 Tree* helpersecond(vector& inorder,int in_begin,int in_end,vector& post,int post_begin,int post_end) { Tree* root =NULL; int mid; int i; if(in_begin > in_end) { return NULL; }...
分类:其他好文   时间:2015-03-30 11:24:10    阅读次数:117
LeetCode – Refresh – Construct Binary Tree from Inorder and Preorder Traversal
Only different with preorder and postorder is that the root start from the beginning for preorder. 1 /** 2 * Definition for binary tree 3 * struct T.....
分类:其他好文   时间:2015-03-19 06:20:26    阅读次数:122
LeetCode – Refresh – Construct Binary Tree from Inorder and Postorder Traversal
For this problem just need to know the structure of two traversal.1. It is hard to find the root node in the inorder traversal but it is easy in posto...
分类:其他好文   时间:2015-03-19 06:19:44    阅读次数:119
397条   上一页 1 ... 23 24 25 26 27 ... 40 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!