/*采用递归法求解。*/
class Solution {
public:
int minDepth(TreeNode* root) {
if(root == nullptr) return 0;
if(root->left == nullptr && root->right == 0) return 1;
if(root->left && !root->right) return 1 + minDepth(root->left);
if(root->right && !root->left) return 1 + minDepth(root->right);
if(root->left && root->right) return 1 + min(minDepth(root->left), minDepth(root->right));
}
};
LeetCode之Minimum Depth of Binary Tree
最新推荐文章于 2020-02-19 02:21:51 发布
