LeetCode 104. Maximum Depth of Binary Tree(二叉树深度)
2024-10-21 20:32:38
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Note: A leaf is a node with no children.
Example:
Given binary tree [3,9,20,null,null,15,7]
,
3
/ \
9 20
/ \
15 7
return its depth = 3.
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int maxDepth(TreeNode* root) {
if (root == NULL) return ; return max(maxDepth(root->left), maxDepth(root->right)) + ;
}
};
最新文章
- [leetcode] 数字游戏
- 关于PetaPoco的T4模板使用
- HTML5 history API实践
- Delphi 过程与函数
- mysql创建用户和创建数据库赋值用户操作权限
- Linux有问必答:怎样解决“XXX is not in the sudoers file”错误
- Firefox插件一键切换兼容IE
- php数组声明、遍历、数组全局变量使用小结
- 转载:linux capability深入分析
- Adapter优化方案的探索
- 1. Server.Transfer和Response.Redirect
- 安装Eclipse Html Editor
- 【视频】零基础学Android开发:蓝牙聊天室APP(四)
- C#中的??是什么意思
- lldpd-0.7.7代码解读(send_pdu部分)
- phpcms2008常用函数小结
- Shopping List
- bcftools将vcf生成bgzip和index格式
- Hive shell 基本命令
- 关于var、let、const的故事