We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 28bf5d3 + f7989cd commit 88b9d51Copy full SHA for 88b9d51
1 file changed
maximum-depth-of-binary-tree/DaleSeo.rs
@@ -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