本文共 477 字,大约阅读时间需要 1 分钟。
思路:动态规划
一棵树是由左子树和右子树组合而成
所以 一个n点数的情况是 根占一个点左子树点0个点可能情况*右子树n-1个点可能情况
左子树点1个点可能情况*右子树n-2个点可能情况 。。。。。。。。。。。。。。。。。。。。。。 左子树点n-1个点可能情况*右子树0个点可能情况这样的所有组合的
public class Solution { public int numTrees(int n) { if(n==0) { return 0; } if(n==1) { return 1; } int record[]=new int [n+1]; record[0]=1; record[1]=1; for(int i=2;i<=n;i++) { int temp=0; for(int j=0;j
转载地址:http://ccuvb.baihongyu.com/