码迷,mamicode.com
首页 >  
搜索关键字:inorder    ( 706个结果
LeetCode --- 94. Binary Tree Inorder Traversal
题目链接:Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return ...
分类:其他好文   时间:2015-04-09 12:00:06    阅读次数:223
【leetcode】Binary Tree Inorder Traversal
与前面的先序遍历相似。此题为后序遍历。C++: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *rig...
分类:其他好文   时间:2015-04-08 23:23:14    阅读次数:159
Leetcode #94 Binary Tree Inorder Traversal
题目链接:https://leetcode.com/problems/binary-tree-inorder-traversal/(非递归实现)二叉树的中序遍历。 1 class Solution 2 { 3 public: 4 vector inorderTraversal(TreeNod...
分类:其他好文   时间:2015-04-05 23:29:30    阅读次数:149
Convert Sorted List to Binary Search Tree--LeetCode
题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 思路:和上面的思想一样,只不过注意找到链表的中间节点的方法 void Inorder(BinTree* root) { if(root == NULL) ...
分类:其他好文   时间:2015-04-04 12:17:29    阅读次数:136
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: Construct Binary Tree from Preorder and Inorder Traversal
题目: Given preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree. 根据前序遍历和中序遍历结果构造二叉树。思路分析: 分析二叉树前序遍历和中序遍历的结果我们发现: 二叉树中序遍...
分类:其他好文   时间:2015-04-03 22:32:25    阅读次数:234
leetcode_105_Construct Binary Tree from Preorder and Inorder Traversal
思路: 1.将中序遍历序列和其对应的下标存储到一个map中,方便下面的查找 2.递归选取前序序列的第一个元素作为树的根节点,然后查找根节点在前序序列中位置inorderIndex,inorderIndex-startInorder可以得到左子树的长度 3.根据左子树的长度和startPreOrder可以求出前序序列中左子树的起始位置 4.从上面可以求出左右子树的前序序列和中序序列的起始位置,递归调用建树过程即可。 PS:其实,对于这道题,有更简单的方法,可根据按前序序列元素出现的顺序依次作为树的根节点进行...
分类:其他好文   时间:2015-04-03 15:17:20    阅读次数:133
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 Inorder Traversal(二叉树中序遍历)
题目: 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].Note: Recursive solution is trivial, c...
分类:其他好文   时间:2015-04-02 20:53:56    阅读次数:141
706条   上一页 1 ... 45 46 47 48 49 ... 71 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!