Skip to content

Commit 0ad9656

Browse files
committedMar 6, 2018
refactor 96
1 parent 63645c4 commit 0ad9656

File tree

1 file changed

+12
-9
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+12
-9
lines changed
 
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fishercoder.solutions;
22

33
/**
4+
* 96. Unique Binary Search Trees
5+
*
46
* Given n, how many structurally unique BST's (binary search trees) that store values 1...n?
57
68
For example,
@@ -15,17 +17,18 @@
1517
*/
1618
public class _96 {
1719

18-
public int numTrees(int n) {
19-
int[] G = new int[n + 1];
20-
G[0] = G[1] = 1;
20+
public static class Solution1 {
21+
public int numTrees(int n) {
22+
int[] G = new int[n + 1];
23+
G[0] = G[1] = 1;
2124

22-
for (int i = 2; i <= n; ++i) {
23-
for (int j = 1; j <= i; ++j) {
24-
int temp = G[j - 1] * G[i - j];
25-
G[i] = G[i] + temp;
25+
for (int i = 2; i <= n; ++i) {
26+
for (int j = 1; j <= i; ++j) {
27+
int temp = G[j - 1] * G[i - j];
28+
G[i] = G[i] + temp;
29+
}
2630
}
31+
return G[n];
2732
}
28-
return G[n];
2933
}
30-
3134
}

0 commit comments

Comments
 (0)
Please sign in to comment.