Skip to content

Commit cc2ca07

Browse files
author
wuyinjun
committed
新题目
1 parent aa8882d commit cc2ca07

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

104. 二叉树的最大深度/Rust/Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "Rust"
3+
version = "0.1.0"
4+
authors = ["wuyinjun <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#[derive(Debug, PartialEq, Eq)]
2+
pub struct TreeNode {
3+
pub val: i32,
4+
pub left: Option<Rc<RefCell<TreeNode>>>,
5+
pub right: Option<Rc<RefCell<TreeNode>>>,
6+
}
7+
8+
impl TreeNode {
9+
#[inline]
10+
pub fn new(val: i32) -> Self {
11+
TreeNode {
12+
val,
13+
left: None,
14+
right: None
15+
}
16+
}
17+
}
18+
19+
struct Solution {
20+
21+
}
22+
23+
// Definition for a binary tree node.
24+
use std::rc::Rc;
25+
use std::cell::RefCell;
26+
use std::cmp;
27+
28+
impl Solution {
29+
pub fn max_depth(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
30+
if let Some(n) = root {
31+
let left = Self::max_depth(n.borrow().left.clone());
32+
let right = Self::max_depth(n.borrow().right.clone());
33+
return 1 + left.max(right);
34+
}
35+
36+
return 0;
37+
}
38+
}
39+
40+
fn main() {
41+
println!("Hello, world!");
42+
}

0 commit comments

Comments
 (0)