File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
main/java/com/smlnskgmail/jaman/leetcodejava/medium
test/java/com/smlnskgmail/jaman/leetcodejava/medium Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .smlnskgmail .jaman .leetcodejava .medium ;
2
+
3
+ // https://leetcode.com/problems/unique-binary-search-trees
4
+ public class UniqueBinarySearchTrees {
5
+
6
+ private final int input ;
7
+
8
+ public UniqueBinarySearchTrees (int input ) {
9
+ this .input = input ;
10
+ }
11
+
12
+ public int solution () {
13
+ int [] catalan = new int [input + 2 ];
14
+ catalan [0 ] = 1 ;
15
+ catalan [1 ] = 1 ;
16
+ for (int i = 2 ; i <= input ; i ++) {
17
+ for (int j = 0 ; j < i ; j ++) {
18
+ catalan [i ] += catalan [j ] * catalan [i - j - 1 ];
19
+ }
20
+ }
21
+ return catalan [input ];
22
+ }
23
+
24
+ }
Original file line number Diff line number Diff line change
1
+ package com .smlnskgmail .jaman .leetcodejava .medium ;
2
+
3
+ import org .junit .Test ;
4
+
5
+ import static org .junit .Assert .assertEquals ;
6
+
7
+ public class UniqueBinarySearchTreesTest {
8
+
9
+ @ Test
10
+ public void defaultTest () {
11
+ assertEquals (
12
+ 5 ,
13
+ new UniqueBinarySearchTrees (3 ).solution ()
14
+ );
15
+ }
16
+
17
+ }
You can’t perform that action at this time.
0 commit comments