mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Update 0222.完全二叉树的节点个数.md
This commit is contained in:
@ -797,6 +797,23 @@ object Solution {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
rust:
|
||||||
|
|
||||||
|
// 递归
|
||||||
|
```rust
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
impl Solution {
|
||||||
|
pub fn count_nodes(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
|
||||||
|
if root.is_none() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
1 + Self::count_nodes(Rc::clone(root.as_ref().unwrap()).borrow().left.clone())
|
||||||
|
+ Self::count_nodes(root.unwrap().borrow().right.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
|
Reference in New Issue
Block a user