104. Maximum Depth of Binary Tree Easy

@problem@discussion
#Tree#Depth-First Search#Breadth-First Search#Binary Tree



1/**
2 * [104] Maximum Depth of Binary Tree
3 *
4 * Given the root of a binary tree, return its maximum depth.
5 * A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/11/26/tmp-tree.jpg" style="width: 400px; height: 277px;" />
9 * Input: root = [3,9,20,null,null,15,7]
10 * Output: 3
11 * 
12 * Example 2:
13 * 
14 * Input: root = [1,null,2]
15 * Output: 2
16 * 
17 *  
18 * Constraints:
19 * 
20 * 	The number of nodes in the tree is in the range [0, 10^4].
21 * 	-100 <= Node.val <= 100
22 * 
23 */
24pub struct Solution {}
25use crate::util::tree::{TreeNode, to_tree};
26
27// problem: https://leetcode.com/problems/maximum-depth-of-binary-tree/
28// discuss: https://leetcode.com/problems/maximum-depth-of-binary-tree/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32// Definition for a binary tree node.
33// #[derive(Debug, PartialEq, Eq)]
34// pub struct TreeNode {
35//   pub val: i32,
36//   pub left: Option<Rc<RefCell<TreeNode>>>,
37//   pub right: Option<Rc<RefCell<TreeNode>>>,
38// }
39// 
40// impl TreeNode {
41//   #[inline]
42//   pub fn new(val: i32) -> Self {
43//     TreeNode {
44//       val,
45//       left: None,
46//       right: None
47//     }
48//   }
49// }
50use std::rc::Rc;
51use std::cell::RefCell;
52impl Solution {
53    pub fn max_depth(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
54        0
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_104() {
66    }
67}
68


Back
© 2025 bowen.ge All Rights Reserved.