mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 01:15:57 +08:00
13 lines
198 B
Go
13 lines
198 B
Go
package leetcode
|
|
|
|
func numTrees(n int) int {
|
|
dp := make([]int, n+1)
|
|
dp[0], dp[1] = 1, 1
|
|
for i := 2; i <= n; i++ {
|
|
for j := 1; j <= i; j++ {
|
|
dp[i] += dp[j-1] * dp[i-j]
|
|
}
|
|
}
|
|
return dp[n]
|
|
}
|