public class Solution { public int numTrees(int n) { //可以采用递归方式,也可以采用线性规划,进行优化 List<Integer> results=new ArrayList<Integer>(); for(int i=0;i<=n;i++) { if(i==0||i==1) results.add(1); else { int res=0; for(int j=0;j<=i-1;j++) { res+=(results.get(j)*results.get(i-1-j)); } results.add(res); } } return results.get(n); } }
96. Unique Binary Search Trees
原文:http://www.cnblogs.com/aguai1992/p/5349944.html