[leetcode]111. Minimum Depth of Binary Tree
2017-06-04 16:11
399 查看
题目链接:https://leetcode.com/problems/minimum-depth-of-binary-tree/#/description
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.
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 minDepth(TreeNode *root) { if(!root) return 0; if(!root->left) return 1 + minDepth(root->right); if(!root->right) return 1 + minDepth(root->left); return 1+min(minDepth(root->left),minDepth(root->right)); } };
相关文章推荐
- LeetCode之Invert Binary Tree(Java版)
- Leetcode 543. Diameter of Binary Tree
- Invert Binary Tree -- leetcode
- LeetCode 111. Minimum Depth of Binary Tree
- Leetcode 654. Maximum Binary Tree 最大二叉树 解题报告
- LeetCode 543. Diameter of Binary Tree
- LeetCode-104. Maximum Depth of Binary Tree
- [leetcode] 543. Diameter of Binary Tree
- [leetcode: Python] 111. Minimum Depth of Binary Tree
- [leetcode]-543. Diameter of Binary Tree
- Leetcode 104. Maximum Depth of Binary Tree
- LeetCode *** 104. Maximum Depth of Binary Tree
- [LeetCode] 111. Minimum Depth of Binary Tree
- LeetCode——111. Minimum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- leetcode-111. Minimum Depth of Binary Tree
- [Leetcode] Binary tree--653. Two Sum IV
- [LeetCode] 104. Maximum Depth of Binary Tree
- 【leetcode】104. Maximum Depth of Binary Tree
- 算法系列(17) Leetcode 104. Maximum Depth of Binary Tree