Skip to content

Commit c794dcf

Browse files
committed
add solution in rust: 111. Minimum Depth of Binary Tree
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
1 parent 009c5d7 commit c794dcf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)