Created
December 31, 2020 15:43
-
-
Save wkdalsgh192/9704659112e74c39a6d186ff6f87a48a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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