Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Last active August 5, 2017 01:27
Show Gist options
  • Save cixuuz/0e576f876552be99cfa64244cf00a4e5 to your computer and use it in GitHub Desktop.
Save cixuuz/0e576f876552be99cfa64244cf00a4e5 to your computer and use it in GitHub Desktop.
[96 Unique Binary Search Trees] #leetcode
public class Solution {
public int numTrees(int n) {
int[] dp = new int[n+1];
dp[0] = dp[1] = 1;
for (int i=2; i <= n; i++) {
for (int j=1; j <= i; j++) {
dp[i] += dp[j-1] * dp[i-j];
}
}
return dp[n];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment