题目:
Invert a binary tree.
4
/ 2 7
/ \ / 1 3 6 9
to
4
/ 7 2
/ \ / 9 6 3 1
解答:
遍历每一个节点 直接交换他们的左右节点
代码:
public static TreeNode invertTr...
分类:
编程语言 时间:
2015-07-06 17:57:58
阅读次数:
163
题目:
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
解题:
求根节点到最近的叶子节点之间的距离
用...
分类:
编程语言 时间:
2015-07-06 16:08:36
阅读次数:
152
题目:
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
解题:
求最大深度 和前面一题类似 用递归遍历就...
分类:
编程语言 时间:
2015-07-06 16:06:14
阅读次数:
143
距离上次使用二叉树快有一年的时间了,是时候重温一次了。【二叉树的定义】二叉树是层次结构,要么是空集,要么是由一个成为根的元素和两颗不同的子二叉树组成(递归定义,子二叉树也可能是空集)。两个子二叉树分别称为左子树和右子树。一个节点的左子树的根节点称为该节点的左孩子,没有孩子的点称为叶节点。二叉查找树的...
分类:
编程语言 时间:
2015-07-06 15:46:43
阅读次数:
165
Swift Compiler Error Binary oprator '+' cannot be applied to operands of type 'UInt16' and 'UInt8'
Swift Compiler Error Binary oprator '+' cannot be applied to operands of type 'Int' and 'Double'...
分类:
移动开发 时间:
2015-07-06 14:21:22
阅读次数:
165
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Hide Tags: Tree ,Depth-first Search/**
* D...
分类:
其他好文 时间:
2015-07-06 12:29:01
阅读次数:
112
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.Hide Tags :Tree ,De...
分类:
其他好文 时间:
2015-07-06 12:25:10
阅读次数:
114
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by...
分类:
其他好文 时间:
2015-07-06 12:24:52
阅读次数:
92
题目:
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
For example:
Given the below binary tree...
分类:
编程语言 时间:
2015-07-06 12:18:44
阅读次数:
94
本文共列出了11个常见的二叉树遍历算法。二叉树的遍历主要有深度优先遍历和广度优先遍历。深度优先遍历包含前序遍历、中序遍历和后序遍历。值得一提的是, 其中的 Morris 算法 可以线性时间不需要额外空间(用户栈或系统栈空间)实现二叉树的前序遍历、中序遍历和后序遍历。关于Morris算法, 可参考ht...
分类:
编程语言 时间:
2015-07-06 11:41:08
阅读次数:
252