Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 34fde8a

Browse files
committed
Add solution 96.
1 parent f0ce081 commit 34fde8a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
3+
/**
4+
* @param Integer $n
5+
* @return Integer
6+
*/
7+
function numTrees($n) {
8+
$dp = array_fill(0, $n + 1, 0);;
9+
$dp[0] = $dp[1] = 1; // null is also a BST;
10+
11+
for($i = 2 ; $i <= $n; $i++){
12+
$dp[$i] = 0;
13+
for($j = 0 ; $j < $i ; $j++){
14+
$dp[$i] += $dp[$j] * $dp[$i - $j - 1];
15+
}
16+
}
17+
return $dp[$n];
18+
}
19+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /