We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9dda2be commit f1620f9Copy full SHA for f1620f9
java/0096-unique-binary-search-trees.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int numTrees(int n) {
3
+ int[] numTree = new int[n+1];
4
+ numTree[0] = numTree[1] = 1;
5
+
6
+ for(int nodes = 2; nodes < n+1; nodes++){
7
+ int total = 0;
8
+ for(int root = 1; root < nodes+1; root++){
9
+ int left = root - 1;
10
+ int right = nodes - root;
11
+ total += numTree[left] * numTree[right];
12
+ }
13
+ numTree[nodes] = total;
14
15
+ return numTree[n];
16
17
+}
0 commit comments