1、minimum-depth-of-binary-tree
2024-08-27 01:44:36
题目描述
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
int run(TreeNode *root){
if (root == nullptr) return ;
if (root->left == nullptr)
{
return run(root->right) + ;
}
if (root->right == nullptr)
{
return run(root->left) + ;
}
int leftDepth = run(root->left);
int rightDepth = run(root->right);
return (leftDepth <= rightDepth) ? (leftDepth + ) : (rightDepth + );
}
最新文章
- linux下redis的安装与部署及基础命令
- 特殊字符导致用正则表达式进行字符串替换失败,Java replaceAll()方法报错Illegal group reference
- 使用mysql数据库,插入数据出现问号(?)的问题,解决方法
- IntelliJ IDEA 开发前的设置
- oracle表空间建立与用户创建删除
- js上传图片及预览功能
- Nginx Location配置总结及基础最佳实践
- linux下添加PATH环境变量
- System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(string, string)已过时的解决办法
- ecshop下启用QQ在线服务,并能实时更新QQ在线状态
- 图像转置的SSE优化(支持8位、24位、32位),提速4-6倍。
- JDBC在springMvc等框架中使用的方式
- Manifest文件的最新理解
- CentOS 7 系统基础配置
- 定位现网环境中最耗费CPU的Java线程
- C# 中Web.config文件的读取与写入
- 【noip 2012】提高组Day2T3.疫情控制
- 蓝牙协议分析(11)_BLE安全机制之SM
- 100-days: sixteen
- Matlab-11:Gausssidel迭代法工具箱