您的位置:首页 > 其它

104. Maximum Depth of Binary Tree

2016-04-01 19:56 337 查看
public class MaximumDepthofBinaryTree104
{
public int maxDepth(TreeNode root) {
int res=0;

Queue<TreeNode> q1=new LinkedList<TreeNode>();
if(root==null)
return 0;
q1.offer(root);
int size=q1.size();
while(!q1.isEmpty())
{
TreeNode temp=q1.poll();
size--;
if(temp.left!=null)
q1.offer(temp.left);
if(temp.right!=null)
q1.offer(temp.right);
if(size==0)
{
res+=1;
size=q1.size();
}
}
return res;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: