leetcode 104 Maximum Depth of Binary Tree(DFS)
2024-09-08 08:15:10
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.
/**
* 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 dfs(TreeNode *r){
if(r==NULL){
return ;
}
return max(dfs(r->left),dfs(r->right)) + ;
} int maxDepth(TreeNode* root) {
return dfs(root);
}
};
最新文章
- 再看ftp上传文件
- 帆布指纹识别(canvas fingerprinting)
- CF459B Pashmak and Flowers (水
- android 事件处理概念簇
- HD1046An Easy Task
- Android隐藏状态栏实现沉浸式体验
- Asp.Net HttpApplication请求管道与Session(二)
- Asset Catalog Creator Free 生成程序内图标的软件
- 【01-14】java ThreadLocal工具类
- 【转载】C# 获取系统时间及时间格式
- Java基础恶补——内存泄露、内存溢出
- .NET Core微服务之路:让我们对上一个Demo通讯进行修改,完成RPC通讯
- selenium APi
- Oracle EBS 计划请求
- Python数据挖掘——基础知识
- C++入门(1)
- SpringMVC札集(09)——拦截器
- C# 3.0-c#5.0 变化
- 使用 ceph 作为 openstack 的后端
- redis的安装和启动linux环境