104. Maximum Depth of Binary Tree

Given the root of a binary tree, return its maximum depth.

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.

Example 1:

复制代码
Input: root = [3,9,20,null,null,15,7]
Output: 3

Example 2:

复制代码
Input: root = [1,null,2]
Output: 2

Constraints:

  • The number of nodes in the tree is in the range [0, 104].

  • -100 <= Node.val <= 100

    class Solution {
    public:
    int maxDepth(TreeNode* root) {
    if(root==nullptr)return 0;
    return max(maxDepth(root->left),maxDepth(root->right))+1;
    }
    };

相关推荐
飞鸿踏雪(蓝屏选手)3 小时前
137 ≤ Chrome 主密钥获取研究
c++·chrome·windows·网络安全·逆向分析
爱滑雪的码农4 小时前
Java基础十七:数据结构
数据结构
多加点辣也没关系5 小时前
数据结构与算法|第二十三章:高级数据结构
数据结构·算法
孬甭_7 小时前
初识数据结构与算法
数据结构
汉克老师9 小时前
GESP6级C++考试语法知识(四、图与树(四))
c++·贪心算法·优先队列·哈夫曼编码·哈夫曼树·gesp6级·gesp六级
子兮曰10 小时前
whisper.cpp 深度解析:从边缘设备到实时语音识别
前端·c++·后端
特种加菲猫10 小时前
二叉搜索树:数据世界的“快速寻路指南”
开发语言·c++
naturerun10 小时前
从数组中删除元素的算法
数据结构·c++·算法
特种加菲猫11 小时前
STL关联容器:Set/Multiset与Map/Multimap详解
开发语言·c++