# leetcode 二叉树最小深度

class Solution {
public:
int run(TreeNode *root) {
if(root==NULL)
return 0;
queue<pair<TreeNode *,int> > q;
q.push(make_pair(root,1));
int min=10000000;
while(!q.empty()){
pair<TreeNode *,int> p;
p=q.front();
q.pop();
TreeNode *tem=p.first;
if(tem->left!=NULL)
q.push(make_pair(tem->left,p.second+1));
if(tem->right!=NULL)
q.push(make_pair(tem->right,p.second+1));
if(tem->left==NULL&&tem->right==NULL){
if(p.second<min)
min=p.second;
}
}
return min;
}
};

class Solution {
public:
int run(TreeNode *root) {
if(root==NULL)
return 0;
if(root->left==NULL)
return run(root->right)+1;
if(root->right==NULL)
return run(root->left)+1;
else
return min(run(root->left),run(root->right))+1;
}
};

• 本文已收录于以下专栏：

## Leetcode 95. Unique Binary Search Trees II及二叉树最大最小深度镜像树总结

95. Unique Binary Search Trees IIDescriptionHintsSubmissionsSolutionsGiven an integer n, generate al...

## 【LeetCode-面试算法经典-Java实现】【111-Minimum Depth of Binary Tree（二叉树的最小深度）】

【111-Minimum Depth of Binary Tree（二叉树的最小深度）】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题　　Given a binary tre...

## [LeetCode]111. Minimum Depth of Binary Tree--二叉树的最小深度

111. Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum d...

## 找出二叉树的最小深度

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the short...

## Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 [java]

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the short...

## 二叉树最大 最小深度

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)