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 009c5d7 commit c794dcfCopy full SHA for c794dcf
src/0101-0200/111 - Minimum Depth of Binary Tree/minimum_depth_of_binary_tree.rs
@@ -0,0 +1,18 @@
1
+impl Solution {
2
+ pub fn min_depth(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
3
+ match root {
4
+ Some(node) => {
5
+ let left = Self::min_depth(node.borrow().left.clone());
6
+ let right = Self::min_depth(node.borrow().right.clone());
7
+
8
+ if left == 0 || right == 0 {
9
+ left.max(right) + 1
10
+ } else {
11
+ left.min(right) + 1
12
+ }
13
14
15
+ None => 0,
16
17
18
+}
0 commit comments