码迷,mamicode.com
首页 >  
搜索关键字:二叉树 层序遍历    ( 10966个结果
【刷题-LeetCode】222. Count Complete Tree Nodes
Count Complete Tree Nodes Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia: In a com ...
分类:其他好文   时间:2020-07-20 15:46:54    阅读次数:80
剑指 offer——树与图篇
7. 重建二叉树 题意:面试题07. 重建二叉树 思路:前序遍历的顺序是“根-左-右”,中序遍历的顺序是“左-中-右”。 那么,对于整棵树前序遍历的结果,第一个值r一定是树的根结点。如果在中序遍历的结果中找到r的位置index,那么index左边的子数组就都是根结点r的左子树的中序遍历结果,inde ...
分类:其他好文   时间:2020-07-19 23:21:29    阅读次数:70
树算法(1)
容易忘的树基本操作 以中序与任意其他方法遍历建二叉树 // 中序与后续为例 struct node { int data; node *l, *r; }; // 中序的hash数组 int hashIn[MAX]; vector<int> in(MAX), post(MAX); node *crea ...
分类:编程语言   时间:2020-07-19 18:09:06    阅读次数:109
LeetCode 102. 二叉树的层序遍历
给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。 示例: 二叉树:[3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其层次遍历结果: [ [3], [9,20], [15,7] ] class Solution( ...
分类:其他好文   时间:2020-07-19 13:49:57    阅读次数:77
LeetCode 94.二叉树的中序遍历
给定一个二叉树,返回它的中序 遍历。 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? ## 迭代 class Solution: def inorderTraversal(self, root: TreeNod ...
分类:其他好文   时间:2020-07-19 11:38:09    阅读次数:55
[编程题] lc[236. 二叉树的最近公共祖先]
[编程题] lc:236. 二叉树的最近公共祖先 题目描述 输入输出例子 思路 使用后续遍历的思想,根据找到了左和右的情况,进行相应的返回结果。 Java代码 /** * Definition for a binary tree node. * public class TreeNode { * i ...
分类:其他好文   时间:2020-07-19 00:39:06    阅读次数:85
逐层打印二叉树
struct BinaryTreeNode { int nvalue=0; BinaryTreeNode* pleft = nullptr; BinaryTreeNode* pright = nullptr; BinaryTreeNode* parent = nullptr;};vector<vec ...
分类:其他好文   时间:2020-07-18 22:37:14    阅读次数:87
LeetCode 951 翻转等价二叉树
题目链接:https://leetcode-cn.com/problems/flip-equivalent-binary-trees/ 解题思路:进行递归,当root1和root2都为空时,返回true,如果双方一个不为空,另一个为空为或双方根节点值不相等false,否则对左右子树分别不翻转判断或翻 ...
分类:其他好文   时间:2020-07-18 21:54:16    阅读次数:70
从上到下打印二叉树 III
题解:层次遍历的基础上加个计数器,偶数层得到的结果反转一下 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeN ...
分类:其他好文   时间:2020-07-18 21:52:24    阅读次数:59
从上到下打印二叉树
解题:利用队列先进先出来实现层次遍历 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ...
分类:其他好文   时间:2020-07-18 19:52:44    阅读次数:68
10966条   上一页 1 ... 36 37 38 39 40 ... 1097 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!