LEETCODE--Minimum Depth of Binary Tree
来源:互联网 发布:淘宝壹心表行全是好评 编辑:程序博客网 时间:2024/05/29 08:08
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.
Subscribe to see which companies asked this question
/** * 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 minlevel = 0; int minDepth(TreeNode* root) { if(!root) return 0; if(!root->left && !root->right) return 1; int leftdepth = minDepth(root->left); int rightdepth = minDepth(root->right); if(leftdepth == 0) return rightdepth+1; if(rightdepth == 0) return leftdepth+1; return min(leftdepth,rightdepth)+1; }};
0 0
- LeetCode: Minimum Depth of Binary Tree
- [Leetcode] Minimum Depth of Binary Tree
- LeetCode : Minimum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- [LeetCode] Minimum Depth of Binary Tree - DFS
- 【leetcode】Minimum Depth of Binary Tree
- LeetCode:Minimum Depth of Binary Tree
- [LeetCode]Minimum Depth of Binary Tree
- [Leetcode]Minimum Depth of Binary Tree
- [leetcode]Minimum Depth of Binary Tree
- Leetcode: Minimum Depth of Binary Tree
- LeetCode-Minimum Depth of Binary Tree
- [leetcode] Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- 【Leetcode】Minimum Depth of Binary Tree
- LeetCode | Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- Test-03
- 一个div在另外一个div中水平垂直居中
- 多线程
- How Did Watson Answer? —— Search & Candidate Generation
- [Cocoa]_[初级]_[如何复制NSView]
- LEETCODE--Minimum Depth of Binary Tree
- 打包过程vs2010(包含卸载功能、生成一个exe文件)
- 批处理查找方件中的关键词
- C++primer第五版第九章学习笔记
- extView设置跑马灯形式不动
- mysql提高查询速度
- kaptcha 验证码使用
- 【小白自学笔记】【机器学习实战】【Python代码逐行理解】CH02
- 从”JAVA“而终 20:深入理解Java的内省与反射