Last active
August 5, 2017 01:27
-
-
Save cixuuz/0e576f876552be99cfa64244cf00a4e5 to your computer and use it in GitHub Desktop.
[96 Unique Binary Search Trees] #leetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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