给定一个二叉树,使用原地算法将它 “压扁” 成链表。示例:给出: 1 / \ 2 5 / \ \ 3 4 6压扁后变成如下: 1 \ 2 \ 3 \ 4 \ 5 \ 6提示:如果您细心观察该扁平树,则会发现每个节点的右侧子节点是以原二叉树前序遍历的次序指向下一个节点的。 详见:https://lee ...
分类:
其他好文 时间:
2018-04-05 01:12:59
阅读次数:
266
给定一棵树的前序遍历与中序遍历,依据此构造二叉树。注意:你可以假设树中没有重复的元素。例如,给出前序遍历 = [3,9,20,15,7]中序遍历 = [9,3,15,20,7]返回如下的二叉树: 3 / \ 9 20 / \ 15 7详见:https://leetcode.com/problems/ ...
分类:
其他好文 时间:
2018-04-04 23:42:14
阅读次数:
399
给定一棵树的中序遍历与后序遍历,依据此构造二叉树。注意:你可以假设树中没有重复的元素。例如,给出中序遍历 = [9,3,15,20,7]后序遍历 = [9,15,7,20,3]返回如下的二叉树: 3 / \ 9 20 / \ 15 7详见:https://leetcode.com/problems/ ...
分类:
其他好文 时间:
2018-04-04 23:29:28
阅读次数:
264
给定一个二叉树,返回其节点值自底向上的层次遍历。 (即按从叶节点所在层到根节点所在的层,逐层从左向右遍历)例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其自自底向上的层次遍历为:[ [15,7], [9,20], [3]]详见:http ...
分类:
其他好文 时间:
2018-04-04 23:27:40
阅读次数:
317
将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树。此题中,一个高度平衡二叉树是指一个二叉树每个节点的左右两个子树的高度差的绝对值不超过1。示例:给定有序数组: [-10,-3,0,5,9],一种可行答案是:[0,-3,9,-10,null,5],它可以表示成下面这个高度平衡二叉搜索树: 0 ...
分类:
编程语言 时间:
2018-04-04 23:17:29
阅读次数:
243
给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶节点的最长路径上的节点数。案例:给出二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回最大深度为 3 。详见:https://leetcode.com/problems/maximum-de ...
分类:
其他好文 时间:
2018-04-04 21:19:02
阅读次数:
197
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes ...
分类:
其他好文 时间:
2018-04-04 21:03:23
阅读次数:
168
An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the ...
分类:
其他好文 时间:
2018-04-04 20:52:47
阅读次数:
171
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any ...
分类:
其他好文 时间:
2018-04-04 20:45:18
阅读次数:
160
给定一个二叉树,返回其按层次遍历的节点值。 (即zhu'ceng'de,从左到右访问)。例如:给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7返回其层次遍历结果为:[ [3], [9,20], [15,7]]详见:https://leetcode ...
分类:
其他好文 时间:
2018-04-04 18:14:04
阅读次数:
215