LeetCode : Minimum Depth of Binary Tree
来源:互联网 发布:遥感大数据特点 编辑:程序博客网 时间:2024/06/02 04:22
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.
/** * 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 minDepth(TreeNode* root) { if(!root) return 0; if(root->left==NULL&&root->right==NULL) return 1; if(root->left==NULL) return minDepth(root->right)+1; else if(root->right==NULL) return minDepth(root->left)+1; else { return min(minDepth(root->left),minDepth(root->right))+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
- 欢迎使用CSDN-markdown编辑器
- elasticsearch源码分析之Rest/RPC 接口解析(八)
- selenium+testNG+maven
- 数组之Next Permutation---leetcode
- 用matlab 保存带标记图像、图片的方法总结
- LeetCode : Minimum Depth of Binary Tree
- CodeForces 321 C.Ciel the Commander(树分治)
- CTreeCtrl展开、收起子节点下所有的节点
- ubuntu安装Hadoop的问题
- Android 展示内容较长,加省略号显示
- 常见正则表达式
- 安装及配置Maven环境变量
- jasig.cas客户端认证成功后ConnectionTimedout
- java设计模式--责任链 Chain of Responsibility