111. Minimum Depth of Binary Tree
来源:互联网 发布:洛阳青峰网络 编辑:程序博客网 时间:2024/06/08 11:04
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.
核心思想是树的递归遍历,同时注意斜树的存在。
class Solution {public: int run(TreeNode *root) { if(root==nullptr){ return 0; } int lc=run(root->left); int rc=run(root->right); if(lc==0){ return rc+1; } else if(rc==0){ return lc+1; } else return min(lc,rc)+1; }};
阅读全文
0 0
- LeetCode 111. Minimum Depth of Binary Tree
- [LeetCode]111.Minimum Depth of Binary Tree
- 【LeetCode】111.Minimum Depth of Binary Tree
- [Leetcode] 111. Minimum Depth of Binary Tree
- 111.Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 【LeetCode】111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- LeetCode *** 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- MVP 详解(上)
- Batch Normalization的作用
- 688. Knight Probability in Chessboard
- 让超出DIV宽度范围的文字自动显示省略号...
- Geo-Plus.VisionLidar.v28.0.01.33.60.Win64 1CD
- 111. Minimum Depth of Binary Tree
- Spring CommonsMultipartResolver 上传文件
- 画画一样开发软件 TERSUS无代码开发工具安装及使用介绍
- yml配置
- 指针函数完成两个数交换
- CLISP 记录: 31. 平台不相关的扩展
- springmvc接收ajax请求参数遇到的坑
- 基因ID
- springmvc 各jar包的作用