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.
1 parent 65f77b6 commit 8c9f7dfCopy full SHA for 8c9f7df
maximum-depth-of-binary-tree/yhkee0404.rs
@@ -0,0 +1,31 @@
1
+// Definition for a binary tree node.
2
+// #[derive(Debug, PartialEq, Eq)]
3
+// pub struct TreeNode {
4
+// pub val: i32,
5
+// pub left: Option<Rc<RefCell<TreeNode>>>,
6
+// pub right: Option<Rc<RefCell<TreeNode>>>,
7
+// }
8
+//
9
+// impl TreeNode {
10
+// #[inline]
11
+// pub fn new(val: i32) -> Self {
12
+// TreeNode {
13
+// val,
14
+// left: None,
15
+// right: None
16
17
18
19
+use std::rc::Rc;
20
+use std::cell::RefCell;
21
+impl Solution {
22
+ pub fn max_depth(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
23
+ match root {
24
+ None => 0,
25
+ Some(u) => {
26
+ let u = u.borrow();
27
+ 1 + Self::max_depth(u.left.clone()).max(Self::max_depth(u.right.clone()))
28
+ }
29
30
31
+}
0 commit comments