mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
添加 0096.不同的二叉搜索树 Rust版本
添加 0096.不同的二叉搜索树 Rust版本
This commit is contained in:
@ -252,6 +252,24 @@ function numTrees(n: number): number {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Rust
|
||||||
|
|
||||||
|
```Rust
|
||||||
|
impl Solution {
|
||||||
|
pub fn num_trees(n: i32) -> i32 {
|
||||||
|
let n = n as usize;
|
||||||
|
let mut dp = vec![0; n + 1];
|
||||||
|
dp[0] = 1;
|
||||||
|
for i in 1..=n {
|
||||||
|
for j in 1..=i {
|
||||||
|
dp[i] += dp[j - 1] * dp[i - j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dp[n]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### C
|
### C
|
||||||
|
|
||||||
```c
|
```c
|
||||||
|
Reference in New Issue
Block a user