原题地址:http://oj.leetcode.com/problems/balanced-binary-tree/题意:判断一颗二叉树是否是平衡二叉树。解题思路:在这道题里,平衡二叉树的定义是二叉树的任意节点的两颗子树之间的高度差小于等于1。这实际上是AVL树的定义。首先要写一个计算二叉树高度的函...
分类:
编程语言 时间:
2014-05-12 14:51:47
阅读次数:
304
题目描述There is a grid size of 1*N. The spanning tree
of the grid connects all the vertices of the grid only with the edges of the
grid, and every vertex...
分类:
其他好文 时间:
2014-05-10 19:00:03
阅读次数:
337
ComBoost项目地址http://comboost.wodsoft.comhttps://github.com/Kation/ComBoost/tree/develop准备工作首先,在Visual
Studio中创建Mvc4项目。然后使用NuGet安装ComBoost程序包。编写实体在Model...
分类:
Web程序 时间:
2014-05-10 05:53:57
阅读次数:
476
Problem DescriptionA tree is a well-known data
structure that is either empty (null, void, nothing) or is a set of one or more
nodes connected by dire...
分类:
其他好文 时间:
2014-05-10 03:18:52
阅读次数:
374
Populating Next Right Pointers in Each
NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode
*right; TreeLi...
分类:
其他好文 时间:
2014-05-10 00:32:56
阅读次数:
326
import osdef tree(top): for path, names, fnames in
os.walk(top): for fname in fnames: yield os.path.join(path, fname) for name
in...
分类:
编程语言 时间:
2014-05-09 23:49:35
阅读次数:
367
前序和中序构建二叉树后序和中序构建二叉树分析:主要思路就是
在中序中找根节点然后划分左右子树,具体如下:1. 查找根节点。 我们知道前序序列的第一个元素 和 后序序列的最后一个元素 肯定是根节点,我们就以此为突破口2.
确定根节点的坐标。 我们在 中序序列中找到 根节点 的下标。3. 分割左右子树。...
分类:
其他好文 时间:
2014-05-09 23:17:30
阅读次数:
458
全排列可以用深搜的方式求解。解答树如下:
可以运行的代码:
import java.util.ArrayList;
import java.util.List;
public class Perm {
public static Integer[] data = {19, 37, 61, 79, 89};
public static int depth;
public...
分类:
其他好文 时间:
2014-05-09 21:09:51
阅读次数:
293
DOS下的tree命令可以把当前路径当做根路径,然后把文件树以树的形式展示出来。这个命令的实现不难,深搜一下文件树就可以了。
import java.io.File;
import java.util.Scanner;
public class Tree {
public static int depth = 0;
public static void main(String[] arg...
分类:
编程语言 时间:
2014-05-09 20:58:45
阅读次数:
361
这道题其实跟二叉搜索树没有什么关系,给定n个节点,让你求有多少棵二叉树也是完全一样的做法。思想是什么呢,给定一个节点数x,求f(x),f(x)跟什么有关系呢,当然是跟他的左右子树都有关系,所以可以利用其左右子树的结论,大问题被成功转化成了小问题。最熟悉的方法是递归和dp,这里显然有大量的重复计算,用dp打表好一些。
后来实验的同学说,这其实是一个Catalan数,上网查了一下,果然啊。Catal...
分类:
其他好文 时间:
2014-05-09 14:47:53
阅读次数:
229