Skip to content

Instantly share code, notes, and snippets.

@wkdalsgh192
Created December 31, 2020 15:43
Show Gist options
  • Save wkdalsgh192/9704659112e74c39a6d186ff6f87a48a to your computer and use it in GitHub Desktop.
Save wkdalsgh192/9704659112e74c39a6d186ff6f87a48a to your computer and use it in GitHub Desktop.
public class BST {
public int numTrees(int n) {
int[] arr = new int[20];
arr[0] = 1;
arr[1] = 1;
int cnt = 0;
for (int i = 2; i <= n; i++) {
cnt = 0;
for (int j = 1; j <= i; j++) cnt += arr[j-1]*arr[i-j];
arr[i] = cnt;
}
return arr[n];
}
public static void main(String[] args) {
int n = 4;
new BST().numTrees(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment