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; } }
相关文章推荐
- 学习进度条04
- EntityFramework优缺点
- 杭电ACM1013
- 图的基本存储的基本方式三
- 山东省第一届ACM大学生程序设计竞赛-Balloons(搜索)
- Ubuntu下搭建samba服务器
- 程序设计——意图与逻辑 (三)
- Hadoop 学习自定义数据类型
- Java for Web学习笔记(十八):Session(2)Session的使用
- Unity3D中C#调用iOS的静态库(*.a)
- 开发软件下载资源
- UDP 聊天室
- 开发软件下载资源
- 二进制字符串转换成中文字符串
- HBase高性能复杂条件查询引擎
- POJ 2104 K-th Number 划分树
- 使用WITH AS提高性能简化嵌套SQL
- pycharm新版注册
- Python特殊语法:filter、map、reduce、lambda
- osgCallback的实现方法