diff --git a/maximum-depth-of-binary-tree-104/Cargo.toml b/maximum-depth-of-binary-tree-104/Cargo.toml new file mode 100644 index 0000000..a9ad825 --- /dev/null +++ b/maximum-depth-of-binary-tree-104/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "maximum-depth-of-binary-tree-104" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/maximum-depth-of-binary-tree-104/src/main.rs b/maximum-depth-of-binary-tree-104/src/main.rs new file mode 100644 index 0000000..a6d5854 --- /dev/null +++ b/maximum-depth-of-binary-tree-104/src/main.rs @@ -0,0 +1,40 @@ +// Definition for a binary tree node. +struct Solution {} + +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn max_depth(root: Option>>) -> i32 { + match root { + None => 0, + Some(node) => { + 1 + std::cmp::max( + Self::max_depth(node.borrow().left.clone()), + Self::max_depth(node.borrow().right.clone()), + ) + } + } + } +} + +fn main() { + println!("Hello, world!"); +}