一、零铺垫 在介绍B树之前,先来看另一棵神奇的树——二叉排序树(Binary Sort Tree),首先它是一棵树,“二叉”这个描述已经很明显了,就是树上的一根树枝开两个叉,于是递归下来就是二叉树了(下图所示),而这棵树上的节点是已经排好序的,具体的排序规则如下: 若左子树不空,则左子树上所有节点的 ...
分类:
数据库 时间:
2020-07-29 21:54:05
阅读次数:
91
题干 Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to ...
分类:
其他好文 时间:
2020-07-29 21:34:20
阅读次数:
77
思路: 公共祖先需要分为三种情况: 1.pq包含在root的左右子树中,则root就是他们公共祖先 2.pq包含在root的右子树中,则公共祖先是右子树 3.pq包含在root的左子树中,则公共祖先在左子树 代码: /** * Definition for a binary tree node. * ...
分类:
其他好文 时间:
2020-07-28 17:01:57
阅读次数:
59
思路: 中序:左->根->右 1.需要一个建立一个栈,首先将左子树放入栈中 2.获取栈顶元素并进行节点判断是否有右子树 3. 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode ...
分类:
其他好文 时间:
2020-07-27 23:50:51
阅读次数:
62
题目链接 https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/ 题解 递归解法 路径:一条从树中任意节点出发,达到任意节点的序列。该路径至少包含一个节点,且不一定经过根节点。 这道题和LeetCode687最长同值路径和Leet ...
分类:
其他好文 时间:
2020-07-27 23:35:37
阅读次数:
74
Given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the s ...
分类:
其他好文 时间:
2020-07-27 15:58:17
阅读次数:
93
解决办法 在项目内添加一个 .npmrc 文件: 代码 //sass sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomj ...
分类:
其他好文 时间:
2020-07-27 15:51:45
阅读次数:
89
思路: 1.使用DFS遍历整颗树 2.二叉树的根节点的范围为INT_MIN,INT_MAX. 3.对于当前节点判断是否合法,合法条件:先遍历左子树的最大值是否小于当前节点的值,在遍历右子树,右子树的最小值是否大于当前节点的值 注意: 根节点的边界为 INT_MIN,INT_MAX 左子树的范围:lo ...
分类:
其他好文 时间:
2020-07-27 13:53:58
阅读次数:
61
二叉排序树 二叉排序树:BST: (Binary Sort(Search) Tree), 对于二叉排序树的任何一个非叶子节点,要求左子节点的值比当前节点的值小,右子节点的值比当前节点的值大。 二叉排序树创建和遍历 ? 一个数组创建成对应的二叉排序树,并使用中序遍历二叉排序树 使用中序遍历的二叉树结点 ...
分类:
编程语言 时间:
2020-07-27 09:35:38
阅读次数:
81
题目链接 https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/ 题解一 递归解法 我写的 说明详见注释 // Problem: LeetCode 111 // URL: https://leetcode-cn.com/probl ...
分类:
其他好文 时间:
2020-07-26 19:32:58
阅读次数:
60