码迷,mamicode.com
首页 >  
搜索关键字:postorder    ( 397个结果
LeetCode 144. 二叉树的前序遍历 Binary Tree Postorder Traversal (Medium)
给定一个二叉树,返回它的 前序 遍历。 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 来源:力扣(LeetCode) 解法一:迭代 解法二:递归 /** * Definition for a binary t ...
分类:其他好文   时间:2020-05-02 11:38:36    阅读次数:52
LeetCode 145: Binary Tree Postorder Traversal
```/** * 145. Binary Tree Postorder Traversal * 1. Time:O(n) Space:O(n) * 2. Time:O(n) Space:O(n) * 3. Time:O(n) Space:O(n) * 4. Time:O(n) Space:O(1) ... ...
分类:其他好文   时间:2020-04-27 13:10:20    阅读次数:48
1119 Pre- and Post-order Traversals
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and ino ...
分类:其他好文   时间:2020-04-24 13:10:38    阅读次数:61
1127 ZigZagging on a Tree
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and ino ...
分类:其他好文   时间:2020-04-22 12:51:03    阅读次数:65
106. 从中序与后序遍历序列构造二叉树
<> 题目描述 根据一棵树的中序遍历与后序遍历构造二叉树。 注意: 你可以假设树中没有重复的元素。 例如,给出 中序遍历 inorder = [9,3,15,20,7] 后序遍历 postorder = [9,15,7,20,3] 返回如下的二叉树: 3 / \ 9 20 / \ 15 7 我的思路 ...
分类:其他好文   时间:2020-04-16 00:46:26    阅读次数:79
LeetCode | 0106. Construct Binary Tree from Inorder and Postorder Traversal从中序与后序遍历序列构造二叉树【Python】
LeetCode 0106. Construct Binary Tree from Inorder and Postorder Traversal从中序与后序遍历序列构造二叉树【Medium】【Python】【二叉树】【递归】 Problem "LeetCode" Given inorder and ...
分类:编程语言   时间:2020-03-18 21:58:48    阅读次数:66
N-ary Tree Postorder Traversal
迭代 /* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<N ...
分类:其他好文   时间:2020-03-16 13:07:10    阅读次数:45
1138 Postorder Traversal(先序+中序=二叉树)
大致题意就是给出一个二叉树的先序、中序遍历序列,要求输出二叉树后序遍历的第一个元素。 1 #include<iostream> 2 using namespace std; 3 4 const int maxn = 50010; 5 int n,pre[maxn],in[maxn],flag = 1 ...
分类:其他好文   时间:2020-03-15 13:35:31    阅读次数:60
p34 二叉树的后续遍历 (leetcode 145)
一:解题思路 这道题目有2种方法,第一种是递归法,第二种是迭代法。2种方法的时间和空间复杂度都为O(n)。 二:完整代码示例 (C++版和Java版) 递归C++: class Solution { public: void postorder(TreeNode* root, vector<int> ...
分类:其他好文   时间:2020-03-14 18:25:21    阅读次数:53
二叉树的遍历
二叉树的遍历 前序遍历 "Leetcode preorder" 中序遍历 "Leetcode inorder" 后续遍历 "Leetcode postorder" Morris Traversal 前序遍历 递归 时间O(n), 空间O(n) 非递归 时间O(n), 空间O(n) 中序遍历 递归 非 ...
分类:其他好文   时间:2020-02-02 15:55:30    阅读次数:63
397条   上一页 1 2 3 4 ... 40 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!