1 public class MaximumDepthofBinaryTree104 2 { 3 public int maxDepth(TreeNode root) { 4 int res=0; 5 6 Queue<TreeNode> ...
1 public class MaximumDepthofBinaryTree104 2 { 3 public int maxDepth(TreeNode root) { 4 int res=0; 5 6 Queue<TreeNode> q1=new LinkedList<TreeNode>(); 7 if(root==null) 8 return 0; 9 q1.offer(root);10 int size=q1.size();11 while(!q1.isEmpty())12 {13 TreeNode temp=q1.poll();14 size--;15 if(temp.left!=null)16 q1.offer(temp.left);17 if(temp.right!=null)18 q1.offer(temp.right); 19 if(size==0)20 {21 res+=1;22 size=q1.size();23 }24 }25 return res;26 27 }28 }
原标题:104. Maximum Depth of Binary Tree
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。