File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 79
79
93|[ Restore IP Addresses] ( ./0093-restore-ip-addresses.js ) |Medium|
80
80
94|[ Binary Tree Inorder Traversal] ( ./0094-binary-tree-inorder-traversal.js ) |Easy|
81
81
95|[ Unique Binary Search Trees II] ( ./0095-unique-binary-search-trees-ii.js ) |Medium|
82
+ 96|[ Unique Binary Search Trees] ( ./0096-unique-binary-search-trees.js ) |Medium|
82
83
98|[ Validate Binary Search Tree] ( ./0098-validate-binary-search-tree.js ) |Medium|
83
84
100|[ Same Tree] ( ./0100-same-tree.js ) |Easy|
84
85
101|[ Symmetric Tree] ( ./0101-symmetric-tree.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 96. Unique Binary Search Trees
3
+ * https://leetcode.com/problems/unique-binary-search-trees/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an integer n, return the number of structurally unique BST's (binary
7
+ * search trees) which has exactly n nodes of unique values from 1 to n.
8
+ */
9
+
10
+ /**
11
+ * @param {number } n
12
+ * @return {number }
13
+ */
14
+ var numTrees = function ( n ) {
15
+ return traverse ( 2 * n ) / ( traverse ( n + 1 ) * traverse ( n ) ) ;
16
+ } ;
17
+
18
+ function traverse ( n ) {
19
+ return n <= 0 ? 1 : n * traverse ( n - 1 ) ;
20
+ }
You can’t perform that action at this time.
0 commit comments