package com.leetcode.problem;
/**
* @author pxu
* @create 2020-04-23 21:38
*/
public class Problem96 {
public static void main(String[] args) {
Problem96 p96 = new Problem96();
System.out.println(p96.numTrees(3));
}
public int numTrees(int n) {
if(n < 0)
return 0;
int [] recorder = new int[n+1];
for (int i = 0; i <= n; i++) {
recorder[i] = -1;
}
recorder[0] = 1;
recorder[1] = 1;
if(recorder[n] > 0)
return recorder[n];
for (int i = 2; i <= n; i++) {
int res = 0;
for (int j = 1; j <= i; j++) {
res = res+(recorder[j-1]*recorder[i-j]);
}
recorder[i] = res;
}
return recorder[n];
}
}
来源:oschina
链接:https://my.oschina.net/u/4489002/blog/3563608