Skip to content

Commit 88b9d51

Browse files
authored
Merge pull request #2468 from DaleStudy/week4
[DaleSeo] WEEK 4 Solutions
2 parents 28bf5d3 + f7989cd commit 88b9d51

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// TC: O(n)
2+
// SC: O(n)
3+
use std::cell::RefCell;
4+
use std::rc::Rc;
5+
6+
impl Solution {
7+
pub fn max_depth(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
8+
match root {
9+
None => 0,
10+
Some(node) => {
11+
let node = node.borrow();
12+
1 + std::cmp::max(
13+
Self::max_depth(node.left.clone()),
14+
Self::max_depth(node.right.clone()),
15+
)
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)